Mission: To protect a page by making it so that only successful form fillouts would work. if (document.referrer.indexOf('referrerCheck.php') != -1) { // This means it IS coming from the form alert("You came from the right place. Stay here.") } else { // This means it is NOT coming from the form alert("You came directly or the wrong place, so go back to the form") //location.href = "URL of FORM" } This is the page with the resource you are trying to protect.