|
All this does is tell the computer the language that is going to be used. You must use this tag, <script>, or <script = "JavaScript"> to make this Confirm or any other JavaScript work.
<!-- Begin hiding here --Since some browsers can't read JavaScript, they just read over the JavaScript code as text and show it to the user as text. This fragment of code begins the commenting out of this text if the user's browser cannot read JavaScript.
/********************************************************************************************These are a bunch of comments which must be left in here if you use this script. The /*,anything after it and before */ are comments. When the computer gets to this part, it skips over it.
if(!confirm("Hello And Welcome to JCL's Tutorial On JavaScript Confirms. You Can Make This Confirm Say Whatever You Want And Do Whatever You Want. Press OK or Yes To Proceed, Or Press No Or Cancel To Go Back To The Site You Were On Before.")) history.go(-1);
This command is an if statement and a confirm. To explain how it works in an easy fashion, I will explain the command in steps.
1. The computer spots an if statement and tries to find out if it is true or not.
2. The computer sees a confirm and activates it to see the truth value of the function, confirm() (The confirm() function is a predefined function (a function that's already been compiled and defined).
3. If the user presses No or Cancel, the confirm returns false so therefore the if statement is true since ! means not or nopt true. If the if statement is true, the visitor will be taken to the page before because the history.go() function tells the computer to go to the site you visited n pages before or after where n is the integer inside of the function's parentheses. If you have -n in the parentheses, your visitor will go to the site he/she was on n pages ago. If n is a positive number, your visitor will go to the site he/she was on n pages after your site. Since n is - 1 in the code I created, if you clicked No or Cancel when the Confirm popped up, you would go to the page you were on before coming to this page. If you change the -1 to 1, it will go forward a page. If the user didn't go to a page before this one and pressed No or
Cancel when the confirm popped up, nothing will happen. If the user pressed Yes or OK, the if statement is false so the computer will skip over it and will stay on the page.
By the way, I didn't make a mistake when I used )) in the last line. If you look at the beginning of the command, you will see a parenthesis after the if and one after the confirm.
This ends the commenting out for browsers unable to read JavaScript.
</script>This command tells the computer that the end of the JavaScript source has been reached. If you do not include this in your document source, the rest of your HTML document will be considered as JavaScript and the computer will not be able to comprehend the rest of the document. Also, the computer will give you Error Alerts.
JCL's HTML & JavaScript Tutorial