The alert() Alternative

Javascript Tutorials


Click on thumbnailed images to enlarge

The normal alert:

<script type="text/javascript">
alert("Hey Ho!");

The more useful alert:

<script type="text/javascript">
if(confirm("This is an adult website\n\nIf you are below 18 click OK")){
window.location = "";
window.location = "actualpage.html";

The more useful alert uses the if-else operator integrated with the confirm() function. The OK button for the confirm() alert means a positive answer to the message.

The else{} section is your alternate action should the criterion (you require) isn't applicable to your message.


\n = returns a newline break

window.location = redirects the current page to the desired page"file.html") = opens a new window

false; = returns no action

Tutorial Comments

No comments yet. Be the first one to comment!

Tutorial Details

Author birdman View profile
Submitted on Mar 30, 2006
Page views 12,232
Favorites 3
Comments 0