473,765 Members | 2,001 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page refresh throws JavaScript error

(I'm rather inexperienced with JavaScript; the failing page was cobbled
together from multiple sources)...

http://pages.prodigy.net/chris_beall/STL/Timeline.html

If JavaScript is not present, or CSS 2 isn't supported, the page just
shows a complete list of dated entries. That's correct.

If JavaScript is present and CSS 2 is supported, a subset of the list is
shown (Example: 9 Jan 2008 is absent) and a button appears in the upper
right, which the user can press to see the complete list. If the button
is pressed, the complete list is shown and the button text changes,
prompting the user to press it again to hide some entries. Pressing the
button again returns things to the initial state (subset of list).
That's correct.

BUT, on Opera (and reportedly Safari), if the user REFRESHes the page,
it appears with the correct version of the button, but the complete
list, instead of the subset, is shown. That's wrong. (Some entries in
the list are hidden by changing, via script, the display property in the
last entry in the associated style sheet.)

It does not fail on Opera if accessing a local copy of the page.
It does not fail in Firefox.

On a refresh (but not when the page is first loaded) the Opera Error
Console shows:
Inline script thread
Error:
name: TypeError
message: Statement on line 23: Cannot convert undefined or null to Object
Backtrace:
Line 23 of inline#1 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html: In function changeIt
theRules[theRules.length-1].style.display = result;
Line 6 of inline#2 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html
changeIt('none' );

It seems to me that either there's a browser bug here (in two browsers)
or there is something I don't know about how JavaScript is processed on
a page refresh from a remote server. I suspect the latter.

Any suggestions would be appreciated.

Thanks,
Chris Beall

Jul 22 '08 #1
6 1839
Chris Beall escribió:
Inline script thread
Error:
name: TypeError
message: Statement on line 23: Cannot convert undefined or null to Object
Backtrace:
Line 23 of inline#1 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html: In function
changeIt
theRules[theRules.length-1].style.display = result;
Line 6 of inline#2 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html
changeIt('none' );
In the page you took this code from (the URL is inside a comment), this
is what they say:

"Unfortunat ely browser incompatibiliti es are so severe that this script
isn't really usable in practice yet."

You may find it easier to loop all your <li>'s and add or remove a
special class, something like "hide":

..hide{
display: none;
}

Use getElementsByCl assName() to find tags with "action" class:

http://www.robertnyman.com/2008/05/2...ame-anno-2008/
And then use addClass() and removeClass() to show or hide:

http://dean.edwards.name/IE7/caveats/
I see nothing wrong in your current approach but you'd need a
cross-browser script to do so and I can't help you with it.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jul 22 '08 #2
pr
Chris Beall wrote:
>
http://pages.prodigy.net/chris_beall/STL/Timeline.html
[...]
On a refresh (but not when the page is first loaded) the Opera Error
Console shows:
Inline script thread
Error:
name: TypeError
message: Statement on line 23: Cannot convert undefined or null to Object
Backtrace:
Line 23 of inline#1 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html: In function
changeIt
theRules[theRules.length-1].style.display = result;
Line 6 of inline#2 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html
changeIt('none' );

It seems to me that either there's a browser bug here (in two browsers)
or there is something I don't know about how JavaScript is processed on
a page refresh from a remote server. I suspect the latter.
Neither; you are simply calling the function before the page has fully
loaded, with predictably unpredictable results.

In this case, document.styleS heets[0].cssRules.lengt h alternates between
zero and 22 (in Opera 9.51), the former case making a nonsense of the line

theRules[theRules.length-1].style.display = result;

since theRules[-1] doesn't exist.

Put your call to changeIt() in body onload. As security, check that
theRules.length 0 before attempting to use its contents.
Jul 22 '08 #3
pr wrote:
Chris Beall wrote:
>>
http://pages.prodigy.net/chris_beall/STL/Timeline.html
[...]
>On a refresh (but not when the page is first loaded) the Opera Error
Console shows:
Inline script thread
Error:
name: TypeError
message: Statement on line 23: Cannot convert undefined or null to
Object
Backtrace:
Line 23 of inline#1 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html: In function
changeIt
theRules[theRules.length-1].style.display = result;
Line 6 of inline#2 script in
http://pages.prodigy.net/chris_beall/STL/Timeline.html
changeIt('none' );

It seems to me that either there's a browser bug here (in two
browsers) or there is something I don't know about how JavaScript is
processed on a page refresh from a remote server. I suspect the latter.

Neither; you are simply calling the function before the page has fully
loaded, with predictably unpredictable results.

In this case, document.styleS heets[0].cssRules.lengt h alternates between
zero and 22 (in Opera 9.51), the former case making a nonsense of the line

theRules[theRules.length-1].style.display = result;

since theRules[-1] doesn't exist.

Put your call to changeIt() in body onload. As security, check that
theRules.length 0 before attempting to use its contents.

pr,

Thanks, I suspected something like that. So, although both my
JavaScript functions and the <linkto the stylesheet are within the
<headof the page, there is no guarantee that they will be completely
processed before the contents of <body>. So it's a race condition and
sometimes I win and sometimes I lose.

If I understand your suggestion, using onload guarantees that the onload
function will not be kicked off until everything else has stabilized, as
loosely documented at
http://www.w3.org/TR/html401/interac...ml#adef-onload

Also, how did you determine the (varying) value of
document.styleS heets[0].cssRules.lengt h? I'd probably add a statement
to display it via a document.write, but perhaps there's another way that
I should know about.

Many thanks,
Chris Beall
Jul 22 '08 #4
pr
Chris Beall wrote:
If I understand your suggestion, using onload guarantees that the onload
function will not be kicked off until everything else has stabilized, as
loosely documented at
http://www.w3.org/TR/html401/interac...ml#adef-onload
Putting it generally, yes. The important thing is that putting the call
in body onload guarantees that DOM collections like document.images and
document.styles heets have been populated and that methods you expect to
work across all the nodes in a document, like getElementsByTa gName() are
in a position to do so.
>
Also, how did you determine the (varying) value of
document.styleS heets[0].cssRules.lengt h? I'd probably add a statement
to display it via a document.write, but perhaps there's another way that
I should know about.
Just the trusty window.alert():

if (document.style Sheets[0].cssRules){
theRules = document.styleS heets[0].cssRules
alert("cssRules " + document.styleS heets[0].cssRules.lengt h);
}

You'll be using that a lot :-)
Jul 22 '08 #5
On Jul 22, 4:18 pm, pr wrote:
Chris Beall wrote:
<snip>
>Also, how did you determine the (varying) value of
document.style Sheets[0].cssRules.lengt h? ...
<snip>
Just the trusty window.alert():

if (document.style Sheets[0].cssRules){
theRules = document.styleS heets[0].cssRules
alert("cssRules " + document.styleS heets[0].cssRules.lengt h);
}

You'll be using that a lot :-)
This is true, but the drawbacks of using - alert - for testing/
reporting/debugging could be mentioned. They can tell you the state at
the point when they open but opening the alert has consequences. It
blocks the execution of the code that opens it, but in doing that
frees to browser to do other things (so race conditions where a script
is racing the browser will be radically altered).

Also, they take the input focus, and so events such as onfocus, onblur
and onchnage may be triggered wherever the focus had been when the -
alert - opened. Making - alerts - problematic when examining
interactions. This problem is quite well illustrated by this page by
John Resig:-

<URL: http://ejohn.org/blog/most-bizarre-ie-quirk >

- where totally bogus conclusions have been drawn as a result of
attempting to examine features of browser/mouse interactions using an
- alert -; Replacing his test code with:-

var count = 0;
setInterval(fun ction(){
window.status = ++count;
}, -1);

- makes an obvious nonsense of all of the conclusions drawn.

Non-blocking reporting that does not take focus used to be commonly
achieved by writing the - window.status - property, which resulted in
the written message appearing in the browser's status bar. Modern
browsers increasingly default to not allowing status bar writing by
scripts, and so need it to be enabled by the user if that technique is
to be used.

However, modern browsers (at least while using an HTML DOM) also allow
writing the innerHTML of elements, giving another easy option for non-
blocking reporting. Though more use while learning and formal testing
than in debugging a 'finished' project (as adding an element to write
into may not be practical or consequence free).
Jul 22 '08 #6
On 22 jul, 18:26, Henry <rcornf...@rain drop.co.ukwrote :
>
Non-blocking reporting that does not take focus used to be commonly
achieved by writing the - window.status - property, which resulted in
the written message appearing in the browser's status bar. Modern
browsers increasingly default to not allowing status bar writing by
scripts, and so need it to be enabled by the user if that technique is
to be used.

However, modern browsers (at least while using an HTML DOM) also allow
writing the innerHTML of elements, giving another easy option for non-
blocking reporting. Though more use while learning and formal testing
than in debugging a 'finished' project (as adding an element to write
into may not be practical or consequence free).
javascript:docu ment.title= "now debugging";

--Jorge.
Jul 24 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
30876
by: Andrew Chalk | last post by:
In a Python script running under CGI, can I programatically redirect the program to another page. Assume that I have a static HTML page that I want displayed (e.g. index.htm). Other than 'print ...' is there any way to redirect to this URL (for example, like Response.Redirect() in ASP)? Many thanks.
18
10145
by: Alan Z. Scharf | last post by:
1. I have a chain of six asynch callbacks initiated by a button, and want the page to refresh at the end of each callback to display A. Results of a SQLServer query showing cumulative running time, and B. A progress bar. 2. I have this working with a refresh timer: <META http-equiv="refresh" content="5">
8
2868
by: Judy Ward | last post by:
I have an index.aspx with frames. The top frame has a navigation bar with a "Login" hyperlink. If the user has already logged in I want this link to change to "Logout". I am using forms-based authentication and think I know how to accomplish this part. My problem is that the top frame does not reload to get to the "If User.Identity.IsAuthenticated Then". Please don't tell me I shouldn't be using frames; this is a school assignment and the...
4
1849
by: Mike | last post by:
On my web app I allow the user to enable or disable the refreshing of the page. I notcied that if the browser window is minimized the page does not refresh, or if it sits a long time without any user interaction(does not happen often) the page does not refresh. Is this a code issue or just how refresh works?
4
3491
by: Dica | last post by:
i apologize for what is no doubt a very rudimentary question, but i'm still trying to wrap my brain around .net coding habits. in classic asp, if i wanted to show search results, i'd just post the form data over to another page or call a showSearchResults sub on the search page. in .net, i can't post to another page, so i need to show the search results on the same page as the search form page. i could write a sub in my code behind that...
10
3478
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario ------------- I have perl script which simply runs a ps on a Solaris server and generates a static html page with all of the code perfectly and this html page works fine when viewing it statically or with a META REFRESH header tag. The idea is to give the user...
5
3752
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi, I used the following code to refresh the parent page, and it works very well (Thanks to Peter Bromberg "). Response.Write("<script language='javascript' type='text/javascript'{ window.opener.location = 'Default.aspx?Reload=100'; }</script>"); Response.Write("<script language='javascript' type='text/javascript'{ self.close(); }</script>");
1
4929
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category order, Input field and a submit button. The Category name is being fetched from the oracle db along with the corresponding Category order. In the corresponding input field (text box) the user enters a new category order which gets stored in...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9951
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9832
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8831
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3924
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.