[Javascript] SAFARI javascript major problem
Troy III Ajnej
trojani2000 at hotmail.com
Sat Jul 12 11:54:33 CDT 2008
I'm suspicious?
Did this post ever made it to our List?
(I allways recieve confirmation. -This once i didn't!).
I've promissed that I'll post it soon after my last relation.
Here it is once again; //these are some of my tests
regarding the problem I haven't solved yet. The scripts
are ready for testing if anybody interested.
p.s.: I still need to store a stylesheet collection in a
global var and be able to use it from my other functions
in safari...
Regards.
......................................................................
From: trojani2000 at hotmail.com
To: trojani2000 at hotmail.com
Subject: RE: [Javascript] SAFARI javascript major problem
Date: Fri, 11 Jul 2008 15:21:26 +0000
I guess that my last shot in the dark was correct. Safari is ?forgetting
the length of stylesheets collection assigned to a global variable.
I'm adding this block of script here to isolate the code that will
cause Safari to stop executing the rest of it.
I hope mail handler will not delete
newline characters and mess the code up as in my previous post.
script type="text/javascript">
var dS = document.styleSheets, theRules;
//Preparing globals for IE's "rule" call separately//
function prepareVar(){
if(dS) theRules = dS[0].rules || dS[0].cssRules;
}
prepareVar();
/script>
script type="text/javascript" language="JavaScript1.0">
/* I've declared javacript language v1.0 "to make sure" that the
* browser is not interpreting this js code in some unknown
* ?modern manner, but who knows if browsers will take this in
* account? Removing it will have no impact at all */
/*
//I need these global vars:
var dS = document.styleSheets;
var theRules = dS[0].rules || dS[0].cssRules;
//I'm depending on a function that depends on "theRules" collection:
function rulesLength(){
if(theRules) alert(theRules.length);
}
*/
// Now, if I write the same function this way
var dS = document.styleSheets, theRules;
function rulesLength(){
if(dS) var theRules = dS[0].rules || dS[0].cssRules;
if(theRules) alert("Rules: "+theRules.length +" Troy [event: \"onclick\"]");
}
document.onclick=rulesLength
// Safari will join the group and report the length of css rules as seen by most.
//Now I'm modifying your (PPK's) published function to only report the length.
function changeIt() {
if (!document.styleSheets) return;
var theRules = new Array();
if (document.styleSheets[0].cssRules)
theRules = document.styleSheets[0].cssRules
else if (document.styleSheets[0].rules)
theRules = document.styleSheets[0].rules
else return;
alert("Rules: "+theRules.length +" PPK [event: \"onload\"]")
}
window.onload=changeIt
//Works perfectly including SAFARI.
/* --------------------------------------------------------------------
* So where is the problem? The problem(s) are, that if you remove the
* multiline script comments from the first version function, -the rest
* of functions will all fail miserably. Including your (PPK) very firm and
* elegant full step conditional procedure.
* ---------------------------------------------*/
// -Now let's try this:
if(dS){alert("1. Stylesheets Length: "+dS.length)}
//Safari is returnig 0. This is definitely what is causing the error.
// How about this:
function getStylesLength(){
if(dS)
//I'm numbering the separate alerts by order they should appear.
alert("2.0 "+dS);
alert("2.1 "+dS+" Length: "+dS.length);
alert("2.2 "+theRules);
alert("2.3 "+theRules+ " Length: "+ theRules.length)
}
getStylesLength()
/* There we have another zero length stylesheets object.
* "dS" is a global var and its assigned value, should outlive at least
* the debug time of the page load, but in SAFARI, if not used immediately
* it 'dies' as soon as the second declaration is parsed.
*/
/*
My final wondering concerns this nebulosity: Is it a SAFARI bug or something else?
Because dS variable is returning "[Object StyleSheetList]" as registered object.
If it really is a style sheet object list than it should have a length of stylesheets
currently available. (in my testing I have two, one embedded, the other is linked)
but SAFARI reports 0 [null], that's WRONG!
*/
//OK let's give it my last try (your procedure):
function lastTrial(){
var cssRlen = new Array();
if (document.styleSheets[0].cssRules)
cssRlen = document.styleSheets[0].cssRules
else if(document.styleSheets[0].rules)
cssRlen = document.styleSheets[0].rules
alert("last entry trial:" +cssRlen.length)
}
lastTrial()
//At this point It fails too!
/* Well, my final thought on this issue is that SAFARI has a serious bug.*/
/script>
Anybody any ideas?
I need a cssrules collection stored in a global var supported by Safari
Is it possible?
Many thanks in advance
p.s.: what I've learned so far when coding for safari: "it is wise to
isolate every function in a separate script element. Long functions,
whenever possible to split in smaller.:)
That's the beauty of "modern". :D
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Troy III
progressive art enterprise
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_________________________________________________________________
Need to know now? Get instant answers with Windows Live Messenger.
http://www.windowslive.com/messenger/connect_your_way.html?ocid=TXT_TAGLM_WL_messenger_072008
More information about the Javascript
mailing list