473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 12633
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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,...

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.