Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #17728 > unrolled thread

To catch an exception

Started by"Tom de Neef" <tdeneef@qolor.nl>
First post2012-12-17 09:50 +0100
Last post2012-12-30 08:42 -0800
Articles 19 — 11 participants

Back to article view | Back to comp.lang.javascript


Contents

  To catch an exception "Tom de Neef" <tdeneef@qolor.nl> - 2012-12-17 09:50 +0100
    Re: To catch an exception Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-17 10:44 +0100
      Re: To catch an exception JJ <jaejunks@nah.meh> - 2012-12-17 10:07 +0000
      Re: To catch an exception "Tom de Neef" <tdeneef@qolor.nl> - 2012-12-17 15:23 +0100
        Re: To catch an exception Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-17 15:33 +0100
          Re: To catch an exception John G Harris <john@nospam.demon.co.uk> - 2012-12-17 15:28 +0000
            Re: To catch an exception Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-17 17:32 +0100
              Re: To catch an exception John G Harris <john@nospam.demon.co.uk> - 2012-12-18 17:01 +0000
                Re: To catch an exception Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-29 14:41 +0100
                  Re: To catch an exception Dr J R Stockton <reply1252@merlyn.demon.co.uk.invalid> - 2012-12-30 16:23 +0000
              Re: To catch an exception Dr J R Stockton <reply1251@merlyn.demon.co.uk.invalid> - 2012-12-18 16:35 +0000
                Re: To catch an exception Andrew Poulos <ap_prog@hotmail.com> - 2012-12-19 22:15 +1100
        Re: To catch an exception Patricia Shanahan <pats@acm.org> - 2012-12-17 07:18 -0800
    Re: To catch an exception JJ <jaejunks@nah.meh> - 2012-12-17 10:04 +0000
      Re: To catch an exception "Tom de Neef" <tdeneef@qolor.nl> - 2012-12-17 14:48 +0100
        Re: To catch an exception Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-17 15:25 +0100
    Re: To catch an exception Tim Streater <timstreater@greenbee.net> - 2012-12-17 16:03 +0000
    Re: To catch an exception Scott Sauyet <scott.sauyet@gmail.com> - 2012-12-18 08:26 -0800
    Re: To catch an exception Bart Van der Donck <bart@nijlen.com> - 2012-12-30 08:42 -0800

#17728 — To catch an exception

From"Tom de Neef" <tdeneef@qolor.nl>
Date2012-12-17 09:50 +0100
SubjectTo catch an exception
Message-ID<50cedccc$0$6950$e4fe514c@news2.news.xs4all.nl>
Can someone indicate what I do wrong here:
{code}
function removeStyleElement(scope) {
  var sheets = document.styleSheets,k,sheet,rules,j,rule,s;
  scope = scope.toLowerCase();
  for (k=sheets.length-1;k>=0;k--) {  // skip the 'fixed' styles in sheet[0]
    sheet = sheets[k];
//    try {
      rules = (sheet.cssRules)?sheet.cssRules:sheet.rules;  //<<=====
//    }
//    catch (err) {return};
    if (rules) {
      for (j=0;j<rules.length;j++) {
         rule = rules[j];
         s = (rule.selectorText)?rule.selectorText:rule;
         if (s.toLowerCase() == scope) {
           if (sheet.removeRule) {sheet.removeRule(j)}
           else { if (sheet.deleteRule) sheet.deleteRule(j) };
         }
      }
    }
  }
}

{/code}

The aim of the function is to remove style rules and it does what it is 
meant to do in IE and Chrome. Not so in FF. When the indicated statement is 
executed, FF will just give up. It jumps out of the function and out of the 
calling functions when the k-loop has reached the bottom sheet (with the 
'fixed' styles loaded from an external stylesheet).
Try..catch around help since then the function terminates properly and 
execution will continue. But why are they necessary? I have no idea how to 
read 'err' in FF.
TIA
Tom 

[toc] | [next] | [standalone]


#17731

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-12-17 10:44 +0100
Message-ID<24673781.rTodiTUJqZ@PointedEars.de>
In reply to#17728
Tom de Neef wrote:

> Can someone indicate what I do wrong here:
> {code}
> […]

Your code is hardly readable and you are not posting the real code.  You are 
indenting your code, but it is missing whitespace in important places to 
that effect.  Also you should not be commenting out lines that are not 
commented out when the code fails to do what it should do.


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

[toc] | [prev] | [next] | [standalone]


#17733

FromJJ <jaejunks@nah.meh>
Date2012-12-17 10:07 +0000
Message-ID<XnsA12CAEE778209jj@0.0.0.15>
In reply to#17731
Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote:
> Tom de Neef wrote:
> 
>> Can someone indicate what I do wrong here:
>> {code}
>> […]
> 
> Your code is hardly readable and you are not posting the real code. 
> You are indenting your code, but it is missing whitespace in important
> places to that effect.  Also you should not be commenting out lines
> that are not commented out when the code fails to do what it should
> do. 
> 
> 
> PointedEars

KNode must've tried really hard to parse it.

[toc] | [prev] | [next] | [standalone]


#17737

From"Tom de Neef" <tdeneef@qolor.nl>
Date2012-12-17 15:23 +0100
Message-ID<50cf2add$0$6910$e4fe514c@news2.news.xs4all.nl>
In reply to#17731
"Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef in bericht 
news:24673781.rTodiTUJqZ@PointedEars.de...
> Tom de Neef wrote:
>
>> Can someone indicate what I do wrong here:
>> {code}
>> [.]
>
> Your code is hardly readable and you are not posting the real code.  You 
> are
> indenting your code, but it is missing whitespace in important places to
> that effect.  Also you should not be commenting out lines that are not
> commented out when the code fails to do what it should do.
>
I do not understand. This is cut&paste from the *.js file. I see a good 
layout, also in JJ's respons.
This code should be working without the try..catch clause. I put it there 
hoping to find out more about the error. And although FF will enter the 
catch, it does not reveal to me why it did that.
I have tried to put a demo together. But the anomalous behaviour does not 
show up in a simple program.
Tom

[toc] | [prev] | [next] | [standalone]


#17739

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-12-17 15:33 +0100
Message-ID<3221544.VYG4icSqfp@PointedEars.de>
In reply to#17737
Tom de Neef wrote:

> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef in bericht
> news:24673781.rTodiTUJqZ@PointedEars.de...

It is supposed to be a attribution _line_, not a novel.

<http://insideoe.com/>

>> Tom de Neef wrote:
>>> Can someone indicate what I do wrong here:
>>> {code}
>>> [.]
>>
>> Your code is hardly readable and you are not posting the real code.  You
>> are indenting your code, but it is missing whitespace in important places
>> to that effect.  Also you should not be commenting out lines that are not
>> commented out when the code fails to do what it should do.
>
> I do not understand. This is cut&paste from the *.js file.

So much the worse.

> I see a good layout, also in JJ's respons.

I can assure you that your opinion of what is “a good layout” differs from 
that of many, if not most, professional programmers, for good reasons.

> This code should be working without the try..catch clause.

Who knows.  I would not take the time to decipher it.

> I put it there hoping to find out more about the error. And although FF
> will enter the catch, it does not reveal to me why it did that.
> I have tried to put a demo together. But the anomalous behaviour does not
> show up in a simple program.

Which indicates that the not so simple version is erroneous.  Rewriting it 
in an easily readable way may reveal the problem already.  Certainly it will 
make your posting and your problem more interesting to others.


PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16

[toc] | [prev] | [next] | [standalone]


#17741

FromJohn G Harris <john@nospam.demon.co.uk>
Date2012-12-17 15:28 +0000
Message-ID<8V1gMFEQozzQFwVT@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>
In reply to#17739
On Mon, 17 Dec 2012 at 15:33:11, in comp.lang.javascript, Thomas
'PointedEars' Lahn wrote:
>Tom de Neef wrote:
>
>> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef in bericht
>> news:24673781.rTodiTUJqZ@PointedEars.de...
>
>It is supposed to be a attribution _line_, not a novel.

For goodness' sake, put a sock in it Thomas.


><http://insideoe.com/>
  <snip>

What have Outlook Express bugs got to do with it?

  John
-- 
John Harris

[toc] | [prev] | [next] | [standalone]


#17743

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-12-17 17:32 +0100
Message-ID<1507338.5fK0Smx0Ns@PointedEars.de>
In reply to#17741
John G Harris wrote:

> […] Thomas 'PointedEars' Lahn wrote:
>> Tom de Neef wrote:
>>> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef […]:
>> It is supposed to be a attribution _line_, not a novel.
> 
> For goodness' sake, put a sock in it Thomas.

“It is supposed to be a attribution _line_, not a sock.”

No, that does not work.

>><http://insideoe.com/>
>   <snip>
> 
> What have Outlook Express bugs got to do with it?

There is the possibilility to get rid of those attribution novels 
automatically.


PointedEars
-- 
Sometimes, what you learn is wrong. If those wrong ideas are close to the 
root of the knowledge tree you build on a particular subject, pruning the 
bad branches can sometimes cause the whole tree to collapse.
  -- Mike Duffy in cljs, <news:Xns9FB6521286DB8invalidcom@94.75.214.39>

[toc] | [prev] | [next] | [standalone]


#17759

FromJohn G Harris <john@nospam.demon.co.uk>
Date2012-12-18 17:01 +0000
Message-ID<6NG$a3EqFK0QFwdZ@J.A830F0FF37FB96852AD08924D9443D28E23ED5CD>
In reply to#17743
On Mon, 17 Dec 2012 at 17:32:38, in comp.lang.javascript, Thomas
'PointedEars' Lahn wrote:
>John G Harris wrote:
>
>> […] Thomas 'PointedEars' Lahn wrote:
>>> Tom de Neef wrote:
>>>> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef […]:
>>> It is supposed to be a attribution _line_, not a novel.
>>
>> For goodness' sake, put a sock in it Thomas.
>
>“It is supposed to be a attribution _line_, not a sock.”

And which RFC says it's one physical line ?


>No, that does not work.
>
>>><http://insideoe.com/>
>>   <snip>
>>
>> What have Outlook Express bugs got to do with it?
>
>There is the possibilility to get rid of those attribution novels
>automatically.

But that web site doesn't say so.

  John
-- 
John Harris

[toc] | [prev] | [next] | [standalone]


#17877

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-12-29 14:41 +0100
Message-ID<1702998.huf0vPK4F7@PointedEars.de>
In reply to#17759
John G Harris wrote:

> Thomas 'PointedEars' Lahn wrote:
>> John G Harris wrote:
>>> […] Thomas 'PointedEars' Lahn wrote:
>>>> Tom de Neef wrote:
>>>>> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef […]:
>>>> It is supposed to be a attribution _line_, not a novel.
>>> For goodness' sake, put a sock in it Thomas.
>> “It is supposed to be a attribution _line_, not a sock.”
> 
> And which RFC says it's one physical line ?

RFC 10042, which will eventually specify Common Sense 1.0 for those in 
desperate need of it.  See also <http://learn.to/quote> and translations.


F'up2 alt.1d

PointedEars
-- 
> If you get a bunch of authors […] that state the same "best practices"
> in any programming language, then you can bet who is wrong or right...
Not with javascript. Nonsense propagates like wildfire in this field.
  -- Richard Cornford, comp.lang.javascript, 2011-11-14

[toc] | [prev] | [next] | [standalone]


#17893

FromDr J R Stockton <reply1252@merlyn.demon.co.uk.invalid>
Date2012-12-30 16:23 +0000
Message-ID<4mxISaEVqG4QFweX@invalid.uk.co.demon.merlyn.invalid>
In reply to#17877
In comp.lang.javascript message <1702998.huf0vPK4F7@PointedEars.de>,
Sat, 29 Dec 2012 14:41:25, Thomas 'PointedEars' Lahn
<PointedEars@web.de> posted:

>John G Harris wrote:
>
>> Thomas 'PointedEars' Lahn wrote:
>>> John G Harris wrote:
>>>> […] Thomas 'PointedEars' Lahn wrote:
>>>>> Tom de Neef wrote:
>>>>>> "Thomas 'PointedEars' Lahn" <PointedEars@web.de> schreef […]:
>>>>> It is supposed to be a attribution _line_, not a novel.
>>>> For goodness' sake, put a sock in it Thomas.
>>> “It is supposed to be a attribution _line_, not a sock.”
>>
>> And which RFC says it's one physical line ?
>
>RFC 10042, which will eventually specify Common Sense 1.0 for those in
>desperate need of it.  See also <http://learn.to/quote> and translations.

RFC10042 refers to a house (which has been sold) in Pukekohe.  The area
seems quite nice, which is more than can be said of Thomas.  Jonah Lomu
was educated there.

-- 
 (c) John Stockton, nr London, UK.  For Mail, see Home Page.  Turnpike, WinXP.
 Web  <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
 Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
 DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.

[toc] | [prev] | [next] | [standalone]


#17770

FromDr J R Stockton <reply1251@merlyn.demon.co.uk.invalid>
Date2012-12-18 16:35 +0000
Message-ID<Q7ySlmOotJ0QFwq3@invalid.uk.co.demon.merlyn.invalid>
In reply to#17743
In comp.lang.javascript message <1507338.5fK0Smx0Ns@PointedEars.de>,
Mon, 17 Dec 2012 17:32:38, Thomas 'PointedEars' Lahn
<PointedEars@web.de> posted:

>There is the possibilility to get rid of those attribution novels
>automatically.

Then, Herr Hauptsturmführer, you should write software to remove them
from your view of News.

-- 
 (c) John Stockton, nr London, UK.  For Mail, see Home Page.  Turnpike, WinXP.
 Web  <http://www.merlyn.demon.co.uk/> - FAQ-type topics, acronyms, and links.
 Command-prompt MiniTrue is useful for viewing/searching/altering files. Free,
 DOS/Win/UNIX now 2.0.6; see <URL:http://www.merlyn.demon.co.uk/pc-links.htm>.

[toc] | [prev] | [next] | [standalone]


#17771

FromAndrew Poulos <ap_prog@hotmail.com>
Date2012-12-19 22:15 +1100
Message-ID<CbudnQUeWvVPPEzNnZ2dnUVZ_rSdnZ2d@westnet.com.au>
In reply to#17770
On 19/12/2012 3:35 AM, Dr J R Stockton wrote:
> In comp.lang.javascript message <1507338.5fK0Smx0Ns@PointedEars.de>,
> Mon, 17 Dec 2012 17:32:38, Thomas 'PointedEars' Lahn
> <PointedEars@web.de> posted:
>
>> There is the possibility to get rid of those attribution novels
>> automatically.
>
> Then, Herr Hauptsturmführer, you should write software to remove them
> from your view of News.

You researched the Nazi party so you could post a "clever" comment about PE!

Andrew Poulos

[toc] | [prev] | [next] | [standalone]


#17740

FromPatricia Shanahan <pats@acm.org>
Date2012-12-17 07:18 -0800
Message-ID<lsmdnSSdFbkxqlLNnZ2dnUVZ_gCdnZ2d@earthlink.com>
In reply to#17737
On 12/17/2012 6:23 AM, Tom de Neef wrote:
...
> I have tried to put a demo together. But the anomalous behaviour does not
> show up in a simple program.

Use that. Start a search for the change that affects the behavior. Start
stripping out code you think is irrelevant from the original program.
Find the change that makes the problem go away. Split that change down
into smaller steps...

Although not showing in a simple program is a good lever for your own
debug, it also makes it a bad case for getting newsgroup help. It means
the problem involves something you don't know is relevant, so your
posting is unlikely to contain the key to the problem.

Patricia

[toc] | [prev] | [next] | [standalone]


#17732

FromJJ <jaejunks@nah.meh>
Date2012-12-17 10:04 +0000
Message-ID<XnsA12CAE7AFCC69jj@0.0.0.15>
In reply to#17728
"Tom de Neef" <tdeneef@qolor.nl> wrote:
> Can someone indicate what I do wrong here:
> {code}
> function removeStyleElement(scope) {
>   var sheets = document.styleSheets,k,sheet,rules,j,rule,s;
>   scope = scope.toLowerCase();
>   for (k=sheets.length-1;k>=0;k--) {  // skip the 'fixed' styles in
>   sheet[0] 
>     sheet = sheets[k];
> //    try {
>       rules = (sheet.cssRules)?sheet.cssRules:sheet.rules;  //<<=====
> //    }
> //    catch (err) {return};
>     if (rules) {
>       for (j=0;j<rules.length;j++) {
>          rule = rules[j];
>          s = (rule.selectorText)?rule.selectorText:rule;
>          if (s.toLowerCase() == scope) {
>            if (sheet.removeRule) {sheet.removeRule(j)}
>            else { if (sheet.deleteRule) sheet.deleteRule(j) };
>          }
>       }
>     }
>   }
> }
> 
> {/code}
> 
> The aim of the function is to remove style rules and it does what it
> is meant to do in IE and Chrome. Not so in FF. When the indicated
> statement is executed, FF will just give up. It jumps out of the
> function and out of the calling functions when the k-loop has reached
> the bottom sheet (with the 'fixed' styles loaded from an external
> stylesheet). Try..catch around help since then the function terminates
> properly and execution will continue. But why are they necessary? I
> have no idea how to read 'err' in FF.
> TIA
> Tom 

The statement in the disabled try...catch shouldn't cause problem. What's 
the exact exception error message when it occurs?

[toc] | [prev] | [next] | [standalone]


#17736

From"Tom de Neef" <tdeneef@qolor.nl>
Date2012-12-17 14:48 +0100
Message-ID<50cf22cc$0$6847$e4fe514c@news2.news.xs4all.nl>
In reply to#17732
"JJ" <jaejunks@nah.meh> schreef in bericht 
news:XnsA12CAE7AFCC69jj@0.0.0.15...
> "Tom de Neef" <tdeneef@qolor.nl> wrote:
>> Can someone indicate what I do wrong here:
>> {code}
>> function removeStyleElement(scope) {
>>   var sheets = document.styleSheets,k,sheet,rules,j,rule,s;
>>   scope = scope.toLowerCase();
>>   for (k=sheets.length-1;k>=0;k--) {  // skip the 'fixed' styles in
>>   sheet[0]
>>     sheet = sheets[k];
>> //    try {
>>       rules = (sheet.cssRules)?sheet.cssRules:sheet.rules;  //<<=====
>> //    }
>> //    catch (err) {return};
>>     if (rules) {
>>       for (j=0;j<rules.length;j++) {
>>          rule = rules[j];
>>          s = (rule.selectorText)?rule.selectorText:rule;
>>          if (s.toLowerCase() == scope) {
>>            if (sheet.removeRule) {sheet.removeRule(j)}
>>            else { if (sheet.deleteRule) sheet.deleteRule(j) };
>>          }
>>       }
>>     }
>>   }
>> }
>>
>> {/code}
>>
>> The aim of the function is to remove style rules and it does what it
>> is meant to do in IE and Chrome. Not so in FF. When the indicated
>> statement is executed, FF will just give up. It jumps out of the
>> function and out of the calling functions when the k-loop has reached
>> the bottom sheet (with the 'fixed' styles loaded from an external
>> stylesheet). Try..catch around help since then the function terminates
>> properly and execution will continue. But why are they necessary? I
>> have no idea how to read 'err' in FF.
>> TIA
>> Tom
>
> The statement in the disabled try...catch shouldn't cause problem. What's
> the exact exception error message when it occurs?

There is no error message. When FF reaches that line, it jumps out and stops 
execution (doesn't pick up in an enclosing block).
With the try .. catch included, it will jump to the catch statement. But I 
do not know how to get information from the 'err' object. The debugger 
doesn't show it.
Tom

[toc] | [prev] | [next] | [standalone]


#17738

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2012-12-17 15:25 +0100
Message-ID<1393459.e97MPUDCx7@PointedEars.de>
In reply to#17736
Tom de Neef wrote:

> "JJ" <jaejunks@nah.meh> schreef […]
>> "Tom de Neef" <tdeneef@qolor.nl> wrote:
>>> Can someone indicate what I do wrong here:
>>> {code}
    ^^^^^^
BTW, this is unnecessary and distracting here.

>>> function removeStyleElement(scope) {
>>>   var sheets = document.styleSheets,k,sheet,rules,j,rule,s;
>>>   scope = scope.toLowerCase();
>>>   for (k=sheets.length-1;k>=0;k--) {  // skip the 'fixed' styles in
>>>   sheet[0]
>>>     sheet = sheets[k];
>>> //    try {
>>>       rules = (sheet.cssRules)?sheet.cssRules:sheet.rules;  //<<=====
>>> //    }
>>> //    catch (err) {return};
>>>     if (rules) {
>>>       for (j=0;j<rules.length;j++) {
>>>          rule = rules[j];
>>>          s = (rule.selectorText)?rule.selectorText:rule;
>>>          if (s.toLowerCase() == scope) {
>>>            if (sheet.removeRule) {sheet.removeRule(j)}
>>>            else { if (sheet.deleteRule) sheet.deleteRule(j) };
>>>          }
>>>       }
>>>     }
>>>   }
>>> }
>>> […]
>> 
>> The statement in the disabled try...catch shouldn't cause problem. What's
>> the exact exception error message when it occurs?
> 
> There is no error message. When FF reaches that line, it jumps out and
> stops execution (doesn't pick up in an enclosing block).

Highly unlikely.

> With the try .. catch included, it will jump to the catch statement. But I
> do not know how to get information from the 'err' object.

By inspecting it?  By document.write()ing, window.alert()ing, 
console.log()ing it before you return?

> The debugger doesn't show it.

It should, and it does, unless its not showing it is related to your bad 
code style (you have the “catch” keyword, its /Block/ statement, and the 
“return” statement in the block on the same line).


PointedEars
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
  -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)

[toc] | [prev] | [next] | [standalone]


#17742

FromTim Streater <timstreater@greenbee.net>
Date2012-12-17 16:03 +0000
Message-ID<timstreater-E299CA.16035617122012@news.individual.net>
In reply to#17728
In article <50cedccc$0$6950$e4fe514c@news2.news.xs4all.nl>,
 "Tom de Neef" <tdeneef@qolor.nl> wrote:

> Can someone indicate what I do wrong here:
> {code}
> function removeStyleElement(scope) {
>   var sheets = document.styleSheets,k,sheet,rules,j,rule,s;
>   scope = scope.toLowerCase();
>   for (k=sheets.length-1;k>=0;k--) {  // skip the 'fixed' styles in sheet[0]
>     sheet = sheets[k];
> //    try {
>       rules = (sheet.cssRules)?sheet.cssRules:sheet.rules;  //<<=====
> //    }
> //    catch (err) {return};
>     if (rules) {
>       for (j=0;j<rules.length;j++) {
>          rule = rules[j];
>          s = (rule.selectorText)?rule.selectorText:rule;
>          if (s.toLowerCase() == scope) {
>            if (sheet.removeRule) {sheet.removeRule(j)}
>            else { if (sheet.deleteRule) sheet.deleteRule(j) };
>          }
>       }
>     }
>   }
> }
> 
> {/code}
> 
> The aim of the function is to remove style rules and it does what it is 
> meant to do in IE and Chrome. Not so in FF. When the indicated statement is 
> executed, FF will just give up. It jumps out of the function and out of the 
> calling functions when the k-loop has reached the bottom sheet (with the 
> 'fixed' styles loaded from an external stylesheet).
> Try..catch around help since then the function terminates properly and 
> execution will continue. But why are they necessary? I have no idea how to 
> read 'err' in FF.

I made myself a little testbed which worked fine in Safari 6.0.2 and FF 
15, FF 17. In FF you need to open the Web console (Tools -> Web 
Developer -> Web Console) to see the messages. Similar in Safari.

I expect if you look in FF's Web console you'll see any error message 
when the "rule = ..." statement fails, which it didn't for me. A quick 
google for "javascript error object" will tell you what 'err' will 
contain.

-- 
Tim

"That excessive bail ought not to be required, nor excessive fines imposed,
nor cruel and unusual punishments inflicted"  --  Bill of Rights 1689

[toc] | [prev] | [next] | [standalone]


#17756

FromScott Sauyet <scott.sauyet@gmail.com>
Date2012-12-18 08:26 -0800
Message-ID<31d13d26-7cb0-45ad-a542-ec4642269c62@c28g2000vby.googlegroups.com>
In reply to#17728
Tom de Neef wrote:
> Can someone indicate what I do wrong here:

> function removeStyleElement(scope) {
>   var sheets = document.styleSheets,k,sheet,rules,j,rule,s;
>   scope = scope.toLowerCase();
>   for (k=sheets.length-1;k>=0;k--) {  // skip the 'fixed' styles in sheet[0]
>     sheet = sheets[k];

I think Patricia is right.  If this is not breaking on simpler test
cases, then your issue is probably not in this code.  But I did notice
that your loop does not match the comment.

You do not skip sheet[0] with this technique.  You would have to
replace `k >= 0` with `k > 0` to skip the first one.

  -- Scott

[toc] | [prev] | [next] | [standalone]


#17892

FromBart Van der Donck <bart@nijlen.com>
Date2012-12-30 08:42 -0800
Message-ID<d8151778-1a65-4187-992b-b7c519bad8c5@googlegroups.com>
In reply to#17728
Tom de Neef wrote:

> Can someone indicate what I do wrong here:
> [snip code]
> The aim of the function is to remove style rules and it does 
> what it is meant to do in IE and Chrome. Not so in FF. When 
> the indicated statement is executed, FF will just give up. 
> [...]

I would not use javascript in this case, but rather reload the page but then with the new style rules (eg. by PHP based on a parameter in the URL).

-- 
 Bart

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web