Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<html>
<head>
<script type="text/javascript">
//This variable tracks whether the user has interacted
//with the form
var hasFormChanged = false;
//This function changes the 'hasFormChanged' variable
//to 'true' - called whenever the user interacts with
//the form.
function setFormChanged(){
hasFormChanged = true;
}
//This function changes the 'hasFormChanged' variable
//to back to 'false' - called only when the form is being
//submitted, as opposed to the page being unloaded some
//other way.
function setFormOK(obj){
hasFormChanged = false;
//This bit just resets the action of the form
//To include the form data - not really important if you
//use asp or cgi or something.
obj.action = 'mailto:dwarf_thrower_2002@yahoo.com?' +
'subject=' + escape('Yes I Will Buy You Beer') +
'&body=' + escape('Name: ' + obj.personName.value + '\n') +
escape('Phone: ' + obj.personPhone.value + '\n') +
escape('Email: ' + obj.personEmail.value + '\n');
}
//This function is called on the document's beforeunload
//event. So any time the page is about to be unloaded -
//Back button, type a new url, close the browser etc -
//this function will run
function checkFormChanged(){
if(hasFormChanged){
msg = 'You are about to leave, you have not yet submitted this form.\nIf you continue your data will not be saved, Do you want to continue?';
event.returnValue = msg;
}
}
</script>
</head>
<!-- Here we set the onunload event to trigger our checking
Function -->
<body onbeforeunload="checkFormChanged();">
<!-- Use the onsubmit action to reset the hasFormChanged
Variable -->
<form action="mailto:dwarf_thrower_2002@yahoo.com" method="get" name="testForm" onsubmit="setFormOK(this);">
<!-- For any form element, use the keypress or click
events to set the hasFormChanged variable to true -->
Name: <input type="text" name="personName" onkeydown="setFormChanged();" /><br />
Phone Number: <input type="text" name="personPhone" onkeydown="setFormChanged();" /><br />
Email: <input type="text" name="personEmail" onkeydown="setFormChanged();" /><br />
<input name="submit" type="submit" value="Submit">
</form>
</body>
</html>