html tutorials web design help css tutorials free web graphics diy search engine optimization

Page Entry Confirmation Script

If you have content that you want to warn people about before letting them enter, or you want them to have to agree to your terms for entering a page, here's a script that requires them to accept your terms or acknowledge and agree to your warning message.

This might be discussions of controversial topics, icky medical descriptions, Java applets, gross pictures, or a host of other topics. The confirmation code on the page that will only let them enter if they click OK in agreement. If they click Cancel, they will be redirected to a page of your choice.

Confirm This!

Add this code after the <body> tag:
<script type="text/JavaScript">
var enter=confirm("Warning! Put your warning message here.")
if (!enter)
window.location="http://www.boogiejack.com"
</script>
Just change the warning message to suit your purpose, and change the redirect page (http://www.boogiejack.com) to the page you want to send them to if they click Cancel instead of OK. Of course, feel free to keep that pointing to my site. I'll take the additional traffic off your hands. :o)

An Important Point!

If you need to use an apostrophe in your alert message you must preface the apostrophe with a backslash. An apostrophe means something else in JavaScript, and using it without placing a backslash will break the code. Using a backslash tells the browser to print the character that follows rather than interpret it as code.

For example, if you wanted to use the word "can't" in your message, you'd write it as:

can\'t
With the code written as it is, if someone clicks the OK button, the page will load. If they click the Cancel button or the red X in the upper right-hand corner they'd be redirected to my front page. That's as it should be, everyone should be redirected to my site. :o)

Well?

Back | Web Design Tutorials Index

Ezine for Webmasters

Bookmark and Share

Almost a Newsletter

Changing list hosts. Will post a new subscribe form shortly.

Did you know...

The member's site has about 100 standards compliant HTML and CSS tutorials, 31 handy reference charts, reprintable content, web graphics, exclusive fonts, free software, free ebooks and more? All this for less than 9 cents a day! [ Details ]
See my fancy bottom! :)