473,698 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When is window.location = "url" executed?

Hello,

the example code is the following(the number in parentheses at the
beginning are just for reference)(The complete HTML file is at the end
of this article):

(1)window.locat ion = 'http://www.google.com' ;
(2)alert("I'm still here!");
(3)window.open( "http://www.slashdot.co m", "_blank");

What happens, is that after the assignment (1) theoretically the rest
of the code shouldn't execute, since the window should be loading a
new URL. But in my browser(Firefox 1.0 on GNU/Linux) the browser also
executes (2) and (3).
It seems that the window is only loaded with the new content after the
script has finished executing.
So is this behaviour wrong or correct?

In all documentations I searched there is no mention of WHEN the new
location should be loaded, if immediately or only after the script
finished executing.

Can anyone try this with IE?

Thank you

Roland

Complete file:

<html:html>
<head>
<script type="text/javascript">
window.location = 'http://www.google.com' ;
alert("I'm still here!");
window.open("ht tp://www.slashdot.co m", "_blank");
</script>
</head>
<body>
Test.
</body>
</html:html>
Jul 23 '05 #1
10 16580
Roland wrote:
<snip>
(1)window.locat ion = 'http://www.google.com' ;
(2)alert("I'm still here!");
(3)window.open( "http://www.slashdot.co m", "_blank");

What happens, is that after the assignment (1) theoretically
the rest of the code shouldn't execute, since the window
should be loading a new URL.
If your expectation is that the assignment to the location property is
the last operation then why is there code after it?

But no, the assignment to the location property does not replace the
page immediately, it might (probably does) make an HTTP request
immediately, that may ultimately return a response that will result in
the page being replaced. But that would be an asynchronous process
anyway so there is not reason to expect the script to terminate at the
point of the assignment.
But in my browser(Firefox 1.0 on GNU/Linux) the browser
also executes (2) and (3).
It seems that the window is only loaded with the new content
after the script has finished executing.
Most likely the page is only replaced when its replacement arrives from
the server.
So is this behaviour wrong or correct?
No specification defines behaviour for assignments to the location
object to the extent that any single behaviour could be expected.
In all documentations I searched there is no mention of
WHEN the new location should be loaded, if immediately
or only after the script finished executing.
It would be unrealistic to expect the page to be replaced prior to the
response to the HTTP request, and no reason to expect the HTTP
request/response process to confine, or be confined by, the execution of
scripts.
Can anyone try this with IE?

<snip>

To what end? If you don't want script to execute after the assignment to
the location property then don't put code after the assignment.

Richard.
Jul 23 '05 #2
You should do an IF with a BODY ONLOAD, but a simple EXIT, as shown
below, ought to answer the question.

<html>
<head>
<script type="text/javascript">
window.location = 'http://www.askblax.com ';
exit(); // stage left
alert("Never gonna reach me!");
window.open("ht tp://www.google.com" , "_blank");

</script>
</head>
<body bgcolor=pink>
Without a valid test before, I will not redirect pages this
way.<BR><BR>Wit hout a valid test before, I will not redirect pages this
way. The only way to reach this line is if a javascript error occurs
before the exit command.
</body>
</html>

http://www.askblax.com

Jul 23 '05 #3
>> Most likely the page is only replaced when its replacement arrives
from
the server. <<

I think you are right.
To what end? If you don't want script to execute after the

assignment to
the location property then don't put code after the assignment. <<

Frames maybe.

Jul 23 '05 #4
askMe wrote on 04 mei 2005 in comp.lang.javas cript:
You should do an IF with a BODY ONLOAD, but a simple EXIT, as shown
below, ought to answer the question.

<html>
<head>
<script type="text/javascript">
window.location = 'http://www.askblax.com ';
exit(); // stage left
exit()?

What language is that, I askYou?

alert("Never gonna reach me!");
window.open("ht tp://www.google.com" , "_blank");

</script>


--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #5
Lee
askMe said:
Most likely the page is only replaced when its replacement arrivesfrom
the server. <<

I think you are right.
To what end? If you don't want script to execute after the

assignment to
the location property then don't put code after the assignment. <<

Frames maybe.


What about frames? That response doesn't seem to make any sense.
The assignment to the location property is going to clear the
rest of the code (sooner or later), anyway.

Jul 23 '05 #6

Lee wrote:
askMe said:
Most likely the page is only replaced when its replacement
arrivesfrom
the server. <<

I think you are right.
To what end? If you don't want script to execute after the

assignment to
the location property then don't put code after the assignment. <<

Frames maybe.


What about frames? That response doesn't seem to make any sense.
The assignment to the location property is going to clear the
rest of the code (sooner or later), anyway.


Your question was "to what end?"...

If I have a frame set of two pages and someone calls one of the pages
on its own, a test could be done from the page to see the current
parent/top window. If the result is not what is expected, redirect to
the parent/top to remake the frameset, else exit the javascript and
continue loading the current page because the page is already loading
as designed.

Expect the unexpected.

Jul 23 '05 #7
It is Javascript, I tellYou. :-)

http://www.askblax.com

Jul 23 '05 #8
askMe wrote:
If I have a frame set of two pages and someone calls one of the pages
on its own, a test could be done from the page to see the current
parent/top window. If the result is not what is expected, redirect to
the parent/top to remake the frameset,
Child's play. Within the frame document:

<head>
...
<script type="text/javascript">
/**
* @author
* (C) 2003, 2004 Thomas Lahn &lt;ty******@Po intedEars.de&gt ;
* Distributed under the GNU GPL v2 and above.
* @optional Object|string o
* Object to be determined an method, i.e. a
* <code>Functio n</code> object assigned as property of
* another object. May also be a string to be evaluated
* and so is applicable to unknown properties.
* @return type boolean
* <code>true</code> if <code>o</code> is a method,
* <code>false</code> otherwise.
* @see #isMethodType()
*/
function isMethod(m)
{
var t;
(m = eval(m)) && (t = typeof m);
return (t == "function" || t == "object");
}

if (typeof parent != "undefined"
&& typeof top != "undefined"
&& parent == top // not in a frameset
&& typeof location != "undefined" )
{
var s = "my_frameset.ht ml?" + encodeURICompon ent(location);
if (isMethod("top. location.replac e"))
{
top.location.re place(s);
}
else
{
top.location = s;
}
}
</script>
...
</head>

Within the frameset document:

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>

<frameset ... onload="if (location.searc h) frames[...].location =
decodeURICompon ent(location.se arch.replace(/^\??(.*)/, '$1'));" ...>
...
</frameset>
else exit the javascript
A client-side script in a UA environment cannot be exited. It can simply
be not further executed, i.e. if no statement or expression follows (or
the current statement results in a fatal error), the script ends.
and continue loading the current page because the page is already loading
as designed.
See above. Redirection will not be performed if the document is part
of a frameset.
Expect the unexpected.


Learn how to use search engines.
PointedEars
Jul 23 '05 #9

Thomas 'PointedEars' Lahn wrote:
askMe wrote:
If I have a frame set of two pages and someone calls one of the pages on its own, a test could be done from the page to see the current
parent/top window. If the result is not what is expected, redirect to the parent/top to remake the frameset,
Child's play. Within the frame document:


Actually, manipulating frames is a pain in the. . . That is why I don't
use them if I don't have to.
<head>
...
<script type="text/javascript">
/**
* @author
* (C) 2003, 2004 Thomas Lahn &lt;ty******@Po intedEars.de&gt ; * Distributed under the GNU GPL v2 and above.
* @optional Object|string o
* Object to be determined an method, i.e. a
* <code>Functio n</code> object assigned as property of
* another object. May also be a string to be evaluated
* and so is applicable to unknown properties.
* @return type boolean
* <code>true</code> if <code>o</code> is a method,
* <code>false</code> otherwise.
* @see #isMethodType()
*/
function isMethod(m)
{
var t;
(m = eval(m)) && (t = typeof m);
return (t == "function" || t == "object");
}

if (typeof parent != "undefined"
&& typeof top != "undefined"
&& parent == top // not in a frameset
&& typeof location != "undefined" )
{
var s = "my_frameset.ht ml?" + encodeURICompon ent(location);
if (isMethod("top. location.replac e"))
{
top.location.re place(s);
}
else
{
top.location = s;
}
}
</script>
...
</head>

Within the frameset document:

<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>

<frameset ... onload="if (location.searc h) frames[...].location =
decodeURICompon ent(location.se arch.replace(/^\??(.*)/, '$1'));" ...>
...
</frameset>
else exit the javascript
A client-side script in a UA environment cannot be exited. It can

simply be not further executed,
Exiting is halting/aborting execution.
i.e. if no statement or expression follows (or
the current statement results in a fatal error), the script ends.

It will exit that way, too, although that is not the best way to end a
script.
and continue loading the current page because the page is already loading as designed.


See above. Redirection will not be performed if the document is part
of a frameset.


Hmmm... I don't think that is true. I struggled with a piece of code
recently that required redirection of frames. At one point, it seemed
to work, but I never got any consistent behavior so I ended up
scrapping it. Also, it is possible to refresh the top frame even if
not the subordinates. Of course all the frames can be loaded/reloaded
in response to events, so no major loss if redirection doesn't work.
Expect the unexpected.


Learn how to use search engines.


Search to learn engine use why.

http://www.askblax.com

PointedEars


Jul 23 '05 #10

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

Similar topics

7
5289
by: NotGiven | last post by:
I changed my POST to GET and find appended to the url, the above string. Why and what can I do to NOT have them appended? Thanks.
6
27755
by: Harald Weiser | last post by:
Hi you out there. I use the following string to go back to a page that's in the history. <A HREF="javascript:history.go('dosearch=0')"> But nothing happens. Using the complete URL makes no difference :-( Suggestions? THX, Harry
4
5974
by: | last post by:
Some time ago I installed VC# 2003, made a small generic project, compile with the allow unsafe flag and I get the error below: "error CS1577: Assembly generation failed -- Unexpected exception processing attribute -- System.ArgumentException: Invalid directory on URL." (If I do not compile with the unsafe flag compiler setting all compiles perfect) After long tracing, I ended up discovering that it is csc.exe installed by the .NET...
5
11042
by: David Webb | last post by:
The problem started when the Working Folder for a project was somehow set to the folder of another project. I set the correct working folder in VSS and deleted the .vbproj files that had been created in the wrong folder on the hard drive. Before I discovered these files, .NET kept trying to create a new project with _1 following the project name. Deleting those files corrected that problem. I deleted the Virtual Directory, rebooted, and...
2
497
by: Luke | last post by:
Hi I have the following code which is an ASP questionnaire using an Access database. (I am using access as I have no choice!). Basically there is an html form which submits the form to the page below and the code below submits the data to the DB and redirects the user. The code works locally on http://localhost or http://127.0.0.1 but when I upload it to a site (I have tried a few and they all error) it says "An error occurred on the...
3
2039
by: VB Programmer | last post by:
When I run my asp.net app locally it runs perfectly. I upload it to another server it runs perfectly. I upload it to a 2nd server and the 1st page (Default.aspx) comes up fine. I then navigate to the 2nd page. When I click on a button (which does a db delete then a response.redirect to Default.aspx) it goes to a blank page and here is the source: <BODY><ASP_SMARTNAV_RDIR url="/deco/Default.aspx"></ASP_SMARTNAV_RDIR></BODY>
3
2317
by: Willy | last post by:
I have a website that uses querystrings on a certain page to show multiple contents. I have created mapped pages to hide the gory details of these querystrings. So instead of details.aspx?ID=kldjlkdjldsjlkds&cat=jjfjfj the client sees products.aspx I also use these "mapped" pages in my sitemap file. This site is multilingual so I have buttons on the page to switch languages.
0
8668
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8597
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
9012
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...
0
8855
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...
1
6515
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4611
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2319
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1992
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.