472,784 Members | 1,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,784 software developers and data experts.

Help with understanding onreadystatechange

Here is a simplified example of what I'm trying to understand.

This works fine:
---------------------------------------------------------------------------
window.open(sURL1,'Window')
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}
---------------------------------------------------------------------------

This never fires onreadystatechange:
---------------------------------------------------------------------------
window.open(sURL1,'Window')
document.location = sURL2
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}
---------------------------------------------------------------------------

I've worked around it by doing:
---------------------------------------------------------------------------
window.open(sURL1,'Window')
window.close()
window.open(sURL2,'Window')
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}
---------------------------------------------------------------------------

I would prefer just to navigate within the already open window (2nd
example), but just can't figure out how. Any help with this would be
extremely appreciated. Even an answer like "you can't do it the way you
want" would at least stop me from pulling my hair out.

Thanks,
Jeremy
Jul 23 '05 #1
7 12563
Lee
Jeremy Gollehon said:
This never fires onreadystatechange:
---------------------------------------------------------------------------
window.open(sURL1,'Window')
document.location = sURL2
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}


That code will open a new window (which it subsequently ignores)
and then changes the location of the current document.
None of the remaining code is likely to be executed because you've
just loaded new content.

Maybe that wasn't the code you had intended to post?

Jul 23 '05 #2
Lee,
Thanks for the reply.
Let me approach this a different way.

Why does this code only fire the 'loading' state of readyState? It never
gets to 'complete'.
----------------------------------------------------------------------------
---
w =
window.open('javascript:document.location.replace( "http://www.google.com")')

w.document.onreadystatechange = function()
{
alert(w.document.readyState)
}
----------------------------------------------------------------------------
----

Thanks again,
Jeremy
Lee wrote:
Jeremy Gollehon said:
This never fires onreadystatechange:
------------------------------------------------------------------------- -- window.open(sURL1,'Window')
document.location = sURL2
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}


That code will open a new window (which it subsequently ignores)
and then changes the location of the current document.
None of the remaining code is likely to be executed because you've
just loaded new content.

Maybe that wasn't the code you had intended to post?



Jul 23 '05 #3
In article <10*************@corp.supernews.com>,
"Jeremy Gollehon" <j_****************@hotmail.com> wrote:
---------------------------------------------------------------------------
window.open(sURL1,'Window')
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}

What is the difference between this and the onload handler?

Robert
Jul 23 '05 #4
I don't have control of the onload handler of the page.
The script I'm working on is client side from a browser (Maxthon) button
plugin. It's basically like writing a bookmarklet without the size
restrictions.

Basically, what I'm trying to accomplish is knowing when a page is fully
loaded. I've been able to do it with the code you quoted below on a new
window, but can't figure out a way to determine if a page has completed
loading when you just navigate within an already open window (tab in
Maxthon's case). The onreadystatechange function doesn't seem to fire when
using document.location.

Maybe there's a way to inject code into the onload handler of a page before
it's done loading? I'm new to javascript and kind of stabbing in the dark.
Thanks for any help you can provide.

-Jeremy
Robert wrote:
In article <10*************@corp.supernews.com>,
"Jeremy Gollehon" <j_****************@hotmail.com> wrote:
------------------------------------------------------------------------- -- window.open(sURL1,'Window')
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}

What is the difference between this and the onload handler?

Robert

Jul 23 '05 #5
Jeremy Gollehon wrote:
This works fine:
---------------------------------------------------------------------------
window.open(sURL1,'Window')
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}
---------------------------------------------------------------------------
This never fires onreadystatechange:
---------------------------------------------------------------------------
window.open(sURL1,'Window')
document.location = sURL2
This navigates you off the current page, everything on the current document,
including the script that follows, is destroyed either immediately, or at some
undetermined (small) amount of time after you issue the above assignment.
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}


--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #6
Lee
Jeremy Gollehon said:

Lee,
Thanks for the reply.
Let me approach this a different way.

Why does this code only fire the 'loading' state of readyState? It never
gets to 'complete'.
----------------------------------------------------------------------------
---
w =
window.open('javascript:document.location.replace ("http://www.google.com")')

w.document.onreadystatechange = function()
{
alert(w.document.readyState)
}


It shows that it is loading immediately, but when the new
content (google) is loaded into the window, it clears the
existing onreadystatechange function, so you never hear
from it again. Loading new content clears all functions.

Jul 23 '05 #7
Lee and Grant,
Your explanations make perfect sense. Thanks for helping out a newbie.

-Jeremy
Grant Wagner wrote:
Jeremy Gollehon wrote:
This works fine:
------------------------------------------------------------------------- -- window.open(sURL1,'Window')
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}
------------------------------------------------------------------------- -- This never fires onreadystatechange:
------------------------------------------------------------------------- -- window.open(sURL1,'Window')
document.location = sURL2


This navigates you off the current page, everything on the current
document, including the script that follows, is destroyed either
immediately, or at some undetermined (small) amount of time after you
issue the above assignment.
document.onreadystatechange = function()
{
if (document.readyState == 'complete')
{
alert('yo')
}
}

Jul 23 '05 #8

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

Similar topics

6
by: Krzysztof Kubiak | last post by:
I'm trying to make use of XMLHTTP object, but I've come across a problem. It seems that there is no way to create dynamic array of such XMLHTTP objects (to make several requests) and handle them...
5
by: Jason Morehouse | last post by:
Hello, PHP programmer in need of some js help. I can't seem to get this function to return the value of xmlhttp.responseText. alert(xmlhttp.responseText) gives me the value I'm looking for. I...
3
by: Andrew Poulos | last post by:
I have a constructor with this IE specific code in it: this.doc.onreadystatechange = this.ready; in a subsequent method I have: alert(this.doc.readyState); this.doc.onreadystatechange =...
1
by: akhil.patel | last post by:
I realize that this may have been asked before, but I could not find a definitive answer. function loadXMLDoc(url, MyFunction) { // use native XMLHttpRequest object if (window.XMLHttpRequest)...
2
by: jhullu | last post by:
hello, I'm writing a program using XMLHttpRequest that works in the main case on IE and mozilla but this code works only on IE ... why ? probleme is located at mark 'HERE' at the end of code....
2
by: petermichaux | last post by:
Hi, I thought it is about time I tried writing some JavaScript with XMLHttpRequest instead of just using the Yahoo! UI library. The simple page below works in both Safari and Opera but I don't...
1
by: sujithegr8 | last post by:
HIii... Its me sujith i've done something with AJAX. but for the rest i need someo ones help.. i've done half the work. there are two tables. "ajax1" and "ajax2" (check db.sql)
7
by: Dan Beanweed | last post by:
I am experimenting with XMLHTTP in a personal website. If I can understand it I would like to use it in a SVG application at work. But I don't get what's going on with my code, especially after...
0
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.