Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > cssRules No Longer Works in FireFox 1.5

Reply
Thread Tools

cssRules No Longer Works in FireFox 1.5

 
 
mephraim
Guest
Posts: n/a
 
      01-22-2006
I have a WYSIWYG editor based on the HTMLArea project that uses the
cssRules object of a stylesheet to add/update stylesheet rules for
table cells. Ever since I upgraded to FireFox 1.5, I get the following
error message when trying to access the cssRules object:

"Access to restricted URI denied"

The code I am trying to execute looks like this:

var currStyleSheet = editor._doc.styleSheets[0];
var currRules = currStyleSheet.cssRules;
var tdIndex = currRules.length;
for(i = 0; i < currRules.length; i++) {
if(currStyleSheet.cssRules.item(i).type == 1) {
//if it is a style rule
var currRule = currRules.item(i)
if (currRule.selectorText.toLowerCase() == "td") {
tdIndex = i;
}
}

}

This code is simply looking for any rules for TD elements. I am at a
loss as to what is going on and/or what changed if FireFox to cause
this error. It worked fine in previous releases of FireFox. The
document that I am trying to access the stylesheet for is within an
IFRAME, which is what I believe is causing the problem. Thanks.

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      01-22-2006


mephraim wrote:

> I have a WYSIWYG editor based on the HTMLArea project that uses the
> cssRules object of a stylesheet to add/update stylesheet rules for
> table cells. Ever since I upgraded to FireFox 1.5, I get the following
> error message when trying to access the cssRules object:
>
> "Access to restricted URI denied"
>
> The code I am trying to execute looks like this:
>
> var currStyleSheet = editor._doc.styleSheets[0];
> var currRules = currStyleSheet.cssRules;


Does the error message not name the exact line number causing the error?
which line is that, the attempt to access
editor._doc
or the attempt to access
currStyleSheet.cssRules

What is the URL of the HTML document with the script, what is the URL of
the iframe? As the error message says "Access to restricted URI denied"
seeing the URIs could help.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
mephraim
Guest
Posts: n/a
 
      01-23-2006
The error occurrs on the line with the following:

var currRules = currStyleSheet.cssRules

I am able to read the stylesheet, but it throws that error when I try
to access cssRules.

I am running this page on a development server
(http://niagara.leepfrog.com/), and the IFRAME is populated with a
series of iframe.document.write() calls, not a SRC. It works when I
try to access cssRules from the main Document sylesheet, but throws the
error when I try to access cssRules in the IFRAME from the Main
Document. Hopefully this clears thins up a little bit.

 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      01-28-2006


mephraim wrote:

> The error occurrs on the line with the following:
>
> var currRules = currStyleSheet.cssRules
>
> I am able to read the stylesheet, but it throws that error when I try
> to access cssRules.
>
> I am running this page on a development server
> (http://niagara.leepfrog.com/), and the IFRAME is populated with a
> series of iframe.document.write() calls, not a SRC.


Do you still experience the problem? Do you have a URL with the example?


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      01-28-2006

mephraim wrote:
> I have a WYSIWYG editor based on the HTMLArea project that uses the
> cssRules object of a stylesheet to add/update stylesheet rules for
> table cells. Ever since I upgraded to FireFox 1.5, I get the following
> error message when trying to access the cssRules object:
>
> "Access to restricted URI denied"
>
> The code I am trying to execute looks like this:
>
> var currStyleSheet = editor._doc.styleSheets[0];
> var currRules = currStyleSheet.cssRules;
> var tdIndex = currRules.length;
> for(i = 0; i < currRules.length; i++) {
> if(currStyleSheet.cssRules.item(i).type == 1) {
> //if it is a style rule
> var currRule = currRules.item(i)
> if (currRule.selectorText.toLowerCase() == "td") {
> tdIndex = i;
> }
> }
>
> }


Uhmm... and who told you that ever worked for Firefox at all? Did you
get yours from mozilla.org ?

Presuming that your style sheet has an ID (the only way to work
reliably with Firefox) and this ID is say "myCSS" then:

document.getElementById('myCSS').sheet.cssRules[0].style.backgroundColor;
and so on...

Works just fine since 1.0.4

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-28-2006
VK wrote:

> mephraim wrote:
>> I have a WYSIWYG editor based on the HTMLArea project that uses the
>> cssRules object of a stylesheet to add/update stylesheet rules for
>> table cells. Ever since I upgraded to FireFox 1.5, I get the
>> following error message when trying to access the cssRules object:
>>
>> "Access to restricted URI denied"
>>
>> The code I am trying to execute looks like this:
>>
>> var currStyleSheet = editor._doc.styleSheets[0];
>> var currRules = currStyleSheet.cssRules;
>> var tdIndex = currRules.length;
>> for(i = 0; i < currRules.length; i++) {
>> if(currStyleSheet.cssRules.item(i).type == 1) {
>> //if it is a style rule
>> var currRule = currRules.item(i)
>> if (currRule.selectorText.toLowerCase() == "td") {
>> tdIndex = i;
>> }
>> }
>>
>> }

>
> Uhmm... and who told you that ever worked for Firefox at all?


It is specified so.

> Did you get yours from mozilla.org ?


Obviously you did not.

> Presuming that your style sheet has an ID (the only way to work
> reliably with Firefox)


Nonsense, Firefox (i.e. the Gecko DOM) provides the document.styleSheets
collection (a reference to a StyleSheetList object) accessed here as
specified in W3C DOM Level 2 Style.

> and this ID is say "myCSS" then:
>
> document.getElementById('myCSS').sheet.cssRules[0].style.backgroundColor;
> and so on...


Nonsense:

> Works just fine since 1.0.4


Of course it does not. A CSSStyleSheet object referred to by the return
value of document.getElementById() here does not have a 'sheet' property
at all. What would also work instead is

document.getElementById('myCSS').cssRules[0].style.backgroundColor;

However this required an ID while the document.styleSheets collection did
not. Unfortunately as usual, the information you provided is factually
flawed and therefore potentially harmful to others.


PointedEars
 
Reply With Quote
 
VK
Guest
Posts: n/a
 
      01-28-2006

Thomas 'PointedEars' Lahn wrote:
> However this required an ID while the document.styleSheets collection did
> not. Unfortunately as usual, the information you provided is factually
> flawed and therefore potentially harmful to others.


as usual 2 months of experiments are defited by one specs reading...

 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-28-2006
VK wrote:

> Thomas 'PointedEars' Lahn wrote:
>> However this required an ID while the document.styleSheets collection did
>> not. Unfortunately as usual, the information you provided is factually
>> flawed and therefore potentially harmful to others.

>
> as usual 2 months of experiments are defited by one specs reading...


What are you babbling about? The Gecko DOM does _not_ specify nor
_implement_ a `sheet' property for CSSStyleSheet objects. However, it has
specified _and_ has _implemented_ the document.styleSheets collection ever
since.

<URL:http://developer.mozilla.org/en/docs/DOM:style>

If your tests showed the opposite, then your tests are flawed. Which would
not be surprising, though.


PointedEars
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      01-28-2006
On 28/01/2006 17:36, Thomas 'PointedEars' Lahn wrote:

> VK wrote:


[snip]

>> Uhmm... and who told you that [styleSheets and cssRules
>> collections] ever worked for Firefox at all?

>
> It is specified so.


Quite right, though more importantly, it is implemented as such (since
at least Moz 1.3 - the earliest Gecko browser I have available at the
moment).

[snip]

> Nonsense, Firefox (i.e. the Gecko DOM) provides the
> document.styleSheets collection (a reference to a StyleSheetList
> object) accessed here as specified in W3C DOM Level 2 Style.


Again, very true.

[snip]

> A CSSStyleSheet object referred to by the return value of
> document.getElementById() here does not have a 'sheet' property at
> all.


An object implementing the CSSStyleSheet interface does not have a sheet
property, as you say, but a LINK or STYLE element that references a
cascading style sheet doesn't implement the CSSStyleSheet interface
directly. Instead, they both implement the LinkStyle interface, which
only has one property, sheet (and that does implement the StyleSheet
interface).

> What would also work instead is
>
> document.getElementById('myCSS').cssRules[0].style.backgroundColor;


You should have tested that; it doesn't (though I'm guilty of the same
charge on occasions when I'm feeling lazy :-/).

[snip]

It seems to me that this should be a security issue: the OP is trying to
access style sheet rules from an IFRAME element that isn't part of the
same domain (from the description, there's no URL). That said, I thought
security issues started when trying to access the document object[1].

Mike


[1] I don't 'do' frames, so I'll plead ignorance, here. It's a
potential starting point, though.

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      01-28-2006
On 28/01/2006 20:30, VK wrote:

[snip]

> as usual 2 months of experiments are defited by one specs reading...


It took you two months to conclude that the Gecko DOM doesn't support
the styleSheets collection, when in fact it does?

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
__parent__ property no longer works in firefox as expected jgabios Javascript 5 04-22-2009 05:21 PM
Firefox Alt-D no longer works? Uto cen Firefox 2 01-29-2007 09:38 PM
cssRules in IE Christopher Benson-Manica Javascript 1 03-03-2005 03:27 PM
Programs taking longer and longer to start up. Help please. Goforit Computer Information 9 07-25-2004 06:34 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM



Advertisments