From: Scott Sauyet on 12 Jan 2010 10:20 On Jan 11, 4:21 pm, Jorge <jo...(a)jorgechamorro.com> wrote: > Ok. Here:http://jorgechamorro.com/cljs/091/ > we've got 4 stylesheets: > > 1.- "a.css" in a <link> tag > 2.- "b.css" imported from a rule @import in a.css > 3.- into a <style> tag. > 2.- "d.css" imported from a rule @import in the <style> stylesheet > > .ownerNode.textContent is "" for #1 (document.styleSheets[0]), and > neither b.css nor d.css are in the document.styleSheets collection... > therefore you've got to walk the rules of the #1 stylesheet, or ... > ¿ what else could you do instead ? No, Thomas is correct here. Ignoring the question of relative URLs, which will arise whether you walk the rules or copy the stylesheets intact, this should copy the *text* that represents the import along with the rest of the rule text. The browser will then request that url in the linked document. I modified your example here, using Thomas' code, modified to put the elements in the document of the inner frame: http://scott.sauyet.com/Javascript/Demo/2010-01-12a/ This has an error in IE which I haven't chased down. Anyone know why IE reports an "Unexpected call to method or property access" on the append child call for the style element? -- Scott
From: Richard Cornford on 12 Jan 2010 11:22 On Jan 12, 3:20 pm, Scott Sauyet wrote: <snip> > I modified your example here, using Thomas' code, modified to > put the elements in the document of the inner frame: > > http://scott.sauyet.com/Javascript/Demo/2010-01-12a/ > > This has an error in IE which I haven't chased down. Anyone > know why IE reports an "Unexpected call to method or property > access" on the append child call for the style element? In IE (from about version 5) elements have a boolean - canHaveChildren - property, which is false for some types of elements, including SCRIPT and STYLE elements. Elements with false - canHaveChildren - properties cannot have children and so attempts to append children to them throw exceptions. Obviously this condition is testable, so changing relevant section of your function to:- var s2 = frameDoc.createElement("style"); if (s1 && s2){ frameHead.appendChild(s2); s2.type = "text/css"; if( (typeof s2.canHaveChildren != 'boolean')|| (s2.canHaveChildren) ){ s2.appendChild( frameDoc.createTextNode( s1.cssText || s1.ownerNode.textContent ) ); }else if( (typeof s2.styleSheet == 'object')&& (typeof s2.styleSheet.cssText == 'string') ){ s2.styleSheet.cssText = ( s1.cssText || s1.ownerNode.textContent ); } } - seems to work OK with IE, and should not change anything for browsers without - canHaveChildren - properties. Note, however, that it was necessary to move the appending of the new STYLE element to the HEAD to prior to any attempts to give it rules as otherwise IE either has not fully set up the elements - styleSheet - object, or it is fatally confused by trying to apply the rules to the owner document (which is either non-existent or a document fragment at that point) (the symptoms of failure prior to moving the point of appending the element being a browser crash). Richard.
From: Scott Sauyet on 12 Jan 2010 12:53 On Jan 12, 11:22 am, Richard Cornford <Rich...(a)litotes.demon.co.uk> wrote: > On Jan 12, 3:20 pm, Scott Sauyet wrote: [ ... ] >> This has an error in IE which I haven't chased down. Anyone >> know why IE reports an "Unexpected call to method or property >> access" on the append child call for the style element? > > In IE (from about version 5) elements have a boolean - canHaveChildren > - property, which is false for some types of elements, including > SCRIPT and STYLE elements. Elements with false - canHaveChildren - > properties cannot have children and so attempts to append children to > them throw exceptions. Obviously this condition is testable, so > changing relevant section of your function to:- > [ ... ] Thank you very much. This works well. A new example is here: http://scott.sauyet.com/Javascript/Demo/2010-01-12b/ I have no idea if the OP is still paying attention, but I think this covers the original request pretty well. -- Scott
From: Jorge on 12 Jan 2010 20:20 On Jan 12, 6:53 pm, Scott Sauyet <scott.sau...(a)gmail.com> wrote: > On Jan 12, 11:22 am, Richard Cornford <Rich...(a)litotes.demon.co.uk> > wrote: > > > On Jan 12, 3:20 pm, Scott Sauyet wrote: > [ ... ] > >> This has an error in IE which I haven't chased down. Anyone > >> know why IE reports an "Unexpected call to method or property > >> access" on the append child call for the style element? > > > In IE (from about version 5) elements have a boolean - canHaveChildren > > - property, which is false for some types of elements, including > > SCRIPT and STYLE elements. Elements with false - canHaveChildren - > > properties cannot have children and so attempts to append children to > > them throw exceptions. Obviously this condition is testable, so > > changing relevant section of your function to:- > > [ ... ] > > Thank you very much. This works well. A new example is here: > > http://scott.sauyet.com/Javascript/Demo/2010-01-12b/ Yep. Clear as an unmuddied lake, Scott. As clear as an azure sky of deepest summer. :-) Thank you very much. -- Jorge.
From: Jorge on 13 Jan 2010 07:08
On Jan 13, 2:20 am, Jorge <jo...(a)jorgechamorro.com> wrote: > > Thank you very much. BTW, there has to be a (good) reason for not including imported (by an @import rule) stylesheets in the document.styleSheets collection. Which one is it ? -- Jorge. |