[Javascript] SAFARI javascript major problem

Troy III Ajnej trojani2000 at hotmail.com
Wed Jul 16 10:32:17 CDT 2008


Greetings Roger.
I think, there is some misconception based on presumption.
I am using "link" to link to my styles, because according tomy recent testing's, "import(s)" will make this fail on other agents too. 
Let alone that Safari has introduced another bug implying to execute the content on its location bar on each "refresh"...
 [!off topic, but,]This new bug will cause an undesired effect on client which accidentally changed some letter on current location, and if he/she, for any reason needs to refresh the current page, it willtry to navigate to a new (wrong) location, supplying him witha blank Safari page containing: "Safari can’t find the file." message. But this is a minor bug and out of our discussion context.
Now let me proceed where I was left. To cut comments and explanations short, I will provide you withmy test page, so you can draw your conclusions from there.
The complete demo code is here (except for the contents of the referred style sheet that you will need to link to).
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"><title>Safari Bug</title>
<link href="anyReady.css" rel="stylesheet" type="text/css">
</head>
<body>
Not working on Safari!
 
<script type="text/javascript">
var dS = document.styleSheets;var theRules = dS[0].rules || dS[0].cssRules;
 alert("seclector name: "+theRules[0].selectorText)
</script>
<!-- Therefore, the following will not work either -->
<script type="text/javascript">
var dS = document.styleSheets;var theRules = dS[0].rules || dS[0].cssRules;
function rulesLength(){ alert("Rules Length: "+theRules.length); }
window.onload = rulesLength
</script></body></html>
Regards. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                      Troy III                         progressive art enterprise~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 



> From: rer at datacompusa.com> To: javascript at lists.evolt.org> Date: Wed, 16 Jul 2008 08:52:53 -0400> Subject: Re: [Javascript] SAFARI javascript major problem> > Troy,> > On Jul 15, 2008, at 4:30 AM, Troy III Ajnej wrote:> > > The:> > alert(document.styleSheets[0].rules[0].selectorText);> > will not work inside the script body.> > -Of course it will work, if, and only if there are no external > > stylesheets> > presently linked to the document, but that's pointless & useless > > equally.> > Sorry I took so long to get back to you. I just got back from > vacation and I am still wading through the backlog.> > Thanks for bringing up this question. It has been educational for me.> > if you link your stylesheet like so: <link rel="stylesheet" > href="test.css" type="text/css"> then > alert(document.styleSheets[0].rules[0].selectorText will work just > fine in Safari. The properties for document.styleSheets[0].rules[0] are> selectorText: body> style: [object CSSStyleDeclaration]> parentStyleSheet: [object CSSStyleSheet]> cssText: body { }> type: 1> parentRule: null> > However, if you _import_ your stylesheet like so:> <style type="text/css">> @import url(test.css);> </style>> the structure of the css is different and your first rule is an import > rule which doesn't have selectorText. If you display the properties > of document.styleSheets[0].rules[0] you get> > href: test.css> styleSheet: [object CSSStyleSheet]> media: [object MediaList]> parentStyleSheet: [object CSSStyleSheet]> cssText: @import url("test.css") ;> type: 3 parentRule: null> > My guess is that ie and firefox are replacing the import rule with the > contents of the imported file, while Safari is creating a hierarchy > that matches the way you have specified your stylesheet in the DOM. > You can get what you want in Safari by following the styleSheet object > like so> > document.styleSheets[0].rules[0].styleSheet.rules[0].selectorText> > or you can change the html to only use linked stylesheets.> > Sorry i don't have better news, but at least we now understand how > Safari works in this case.> > Roger> --> Roger Roelofs> Datacomp Appraisal Services> 3215 Eaglecrest, NE> Grand Rapids, MI 49525> > _______________________________________________> Javascript mailing list> Javascript at lists.evolt.org> http://lists.evolt.org/mailman/listinfo/javascript
_________________________________________________________________
With Windows Live for mobile, your contacts travel with you.
http://www.windowslive.com/mobile/overview.html?ocid=TXT_TAGLM_WL_mobile_072008


More information about the Javascript mailing list