473,520 Members | 2,503 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.location = 'http://www.google.com';
(2)alert("I'm still here!");
(3)window.open("http://www.slashdot.com", "_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("http://www.slashdot.com", "_blank");
</script>
</head>
<body>
Test.
</body>
</html:html>
Jul 23 '05 #1
10 16535
Roland wrote:
<snip>
(1)window.location = 'http://www.google.com';
(2)alert("I'm still here!");
(3)window.open("http://www.slashdot.com", "_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("http://www.google.com", "_blank");

</script>
</head>
<body bgcolor=pink>
Without a valid test before, I will not redirect pages this
way.<BR><BR>Without 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.javascript:
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("http://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******@PointedEars.de&gt;
* Distributed under the GNU GPL v2 and above.
* @optional Object|string o
* Object to be determined an method, i.e. a
* <code>Function</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.html?" + encodeURIComponent(location);
if (isMethod("top.location.replace"))
{
top.location.replace(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.search) frames[...].location =
decodeURIComponent(location.search.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******@PointedEars.de&gt; * Distributed under the GNU GPL v2 and above.
* @optional Object|string o
* Object to be determined an method, i.e. a
* <code>Function</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.html?" + encodeURIComponent(location);
if (isMethod("top.location.replace"))
{
top.location.replace(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.search) frames[...].location =
decodeURIComponent(location.search.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
askMe wrote:
Thomas 'PointedEars' Lahn wrote:
askMe wrote:
> If I have a frame set of two pages and someone calls one of the pages ^^^
*Please* either don't use Google Groups interface for posting or learn
how to post readable quotes.

[quoting repaired:]
> 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. . .


Why?
That is why I don't use them if I don't have to.
Your logic is erroneous. What if client-side scripting is not even
supported?

I don't use frames if there are other viable solutions because otherwise
it would reduce usability. Think of no-script UAs, smaller viewports,
bookmarks etc.
[...]
It was completely unnecessary to quote all my code since you are not
directly referring to it. Please read the FAQ (Notes) and learn how
to post.
> 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.


Yes. Just what I wrote: A client-side script in a UA cannot be
exited, it can only be not further executed. This is different.
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.


It is the only way in a client-side script in a UA. You could only wrap
all the global code in single global method, call that method from global
execution context and use the `return' statement to leave the local
execution context. But that would be not different to what I wrote:
Execution then stops because after the method call no statement follows
in global execution context.
> 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.


Does not matter here what you may think. It will not be performed then
because parent != top; the condition will evaluate to `false', so the
`&&' operation will evaluate to `false' and so the parameter of the `if'
statement will evaluate to `false' which will cause the bytecode
interpreter to skip the compiled block that follows:

| [...]
| if (typeof parent != "undefined"
| && typeof top != "undefined"
| && parent == top // not in a frameset
| && typeof location != "undefined")
| {
| // [redirection]
| }
| [no further statement or expression]
I struggled with a piece of code recently that required redirection of
frames.
But not with my piece of code.
At one point, it seemed to work, but I never got any consistent behavior
so I ended up scrapping it.
You may want to post it (or a link to it if it's too big) here for a more
competent evaluation.
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.


I don't know what this has to do with the task discussed.
> Expect the unexpected.

Learn how to use search engines.


Search to learn engine use why.


Back your pardon?
PointedEars
Jul 23 '05 #11

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

Similar topics

7
5276
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
27741
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
5945
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...
5
11012
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...
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...
3
2019
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...
3
2310
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...
0
7448
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. ...
0
7611
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...
1
7175
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...
0
7573
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...
0
4795
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...
0
3287
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1659
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
1
842
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
515
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...

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.