Automatically Redirecting the User
o We have already briefly seen the use of browser redirection in chapter 4.
o To formulate the idea more completely, in order to redirect the user to a different page, you set the location property of the document objects.
o As we saw in chapter 6, we can use the assignment operator here. For example:
document.location = “http://www.bbc.co.uk/”; document.location = “chapter_4.html”;
Project
o Open your previous project file, and save it under the name chapter_9_redirect.html.
o Save another copy of the file, this time called chapter_9.html.
o Make sure both files are saved in the same folder, and that you have chapter_9.html open in your editor.
o Remove all script from between the script tags, except for your browser hiding lines. Make sure that the script tags are still in the head section of the page.
o Now, add a single statement to this script that will automatically redirect the user to the page
chapter_9_redirect.html as soon as the page is loaded into a browser.
o Finally, add a header tag to the body section of the page containing the text “You can’t see me!”.
o Close this page, don’t check it in a browser yet, and open the page chapter_9_redirect.html in your editor.
o Remove all JavaScript from this page (including your script tags) and ensure that only HTML remains on the page.
o Add a header tag to the body section of the page containing the text “But you can see ME!”.
o Save this page, and load the page chapter_9.html into your browser.
Experiment with various positions for the script tags on chapter_9.html to see if you can make the header appear before the redirection.
Recent Comments