Publishing System Settings Logout Login Register
Redirect your browser after alerting the user
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on May 7th, 2007
15549 views
JavaScript
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.");
location = "http://www.mysite.com";

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>
<head>
<script type="text/javascript">
alert("Click OK to redirect.");
location = "http://www.mysite.com";
</script>
</head>
<body>
</body>
</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.
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
David Knight

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top