Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q350 Why does the code continue to be interpreted even after I've requested that another document be loaded?

irt.org | Knowledge Base | JavaScript | General | Q350 [ previous next ]

Q350 Why does the code continue to be interpreted even after I've requested that another document be loaded?

If say you have code like:

if (x == y) {
    location.href = 'http://www.irt.org/';
}
document.write('<P>blah blah');

Then what happens is that JavaScript changes the href property of a document object to a text string, the *browser* knows that this means "go get http://www.irt.org/' - so it does, but JavaScript doesn't know this, it just knows that it has changed the value of an objects property. The JavaScript code continues to be interpreted.

To stop this from occurring do not have any JavaScript code after the request to load another document:

if (x == y) {
    location.href = 'http://www.irt.org/';
}
else {
    document.write('<P>blah blah');
}

If however you need both to occur, i.e. load another document but also output text to the current document then swap the order around:

document.write('<P>blah blah');
if (x == y) {
    location.href = 'http://www.irt.org/';
}

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.