Tutorial
Click on thumbnailed images to enlarge
The normal alert:
<script type="text/javascript">
alert("Hey Ho!");
</script>
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 = "http://alternatewebsite.com";
}else{
window.location = "actualpage.html";
}
</script>
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.
NOTE:
\n = returns a newline break
window.location = redirects the current page to the desired page
window.open("file.html") = opens a new window
false; = returns no action
<script type="text/javascript">
alert("Hey Ho!");
</script>
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 = "http://alternatewebsite.com";
}else{
window.location = "actualpage.html";
}
</script>
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.
NOTE:
\n = returns a newline break
window.location = redirects the current page to the desired page
window.open("file.html") = opens a new window
false; = returns no action
Tutorial Comments
No comments yet. Be the first one to comment!