Posted on May 7th, 2007
21437 views
This tutorial is intended for Beginner JavaScript users, understanding of JavaScript required.
This is the fourth of five JavaScript redirection tutorials I will be writing. The files used in this tutorial are available for download. (.zip) Table of contents 1 - Introduction 2 - Alert & Redirection 3 - Conclusion -Introduction In this tutorial you will learn how to alert the user before redirecting the browser. We will be using the JavaScript alert() function as well as the location property. Lets get started - Alert The JavaScript alert() function pops up a window with an OK button. (We will be using the OK button as an acceptance to redirect.) Lets take a look at code for the pop-up that the alert() function creates. alert("Click OK to redirect."); It is a small function that makes a simple pop-up. You can replace the text inside the quotes with anything you want. - Redirection Now lets add our location property combined with our alert() function. alert("Click OK to redirect."); Our code now tells the browser to make a pop-up box with the text inside our quotes, then redirect after the OK button is clicked. Now lets put insert it into a basic HTML page. <html> - Conclusion You can also include the JavaScript in an external file by using <script type="text/javascript" src="myjavascript.js" /> Both ways are included in the file download. You now know how to alert the user before redirecting your browser. The files used in this tutorial are available for download. |