View Full Version : Javascript (Enter From...Only)
dnirvine
09-19-03, 12:15 AM
I know there is a script somewhere on the net I saw before but I cannot find it again.
It is a script that will allow a user to see a page only if they come from a certain page. I would like to know what this code is if possible. Thanks.
Chroder
09-22-03, 04:13 PM
Something like this,
<script language="javascript">
<!--
var which_page = "mypage.html";
var redirect = "http://mypage.html";
if(document.referrer.indexOf(which_page) == -1)
{
document.write("You came from the wrong page!");
}
else
{
window.location = redirect;
}
-->
</script>
If a user did NOT come from the page in "which_page" variable, it will print out a message. If they did then they get redirected to the page in the "Redirect" variable. You might not want to include the entire URL in the "which_page" variable because the indexOf function checks to see if the string is part of the referral, so if you were checking "http://www.mypage.com" and the user came from "http://mypage.com", then they'd see the error message.
dnirvine
09-22-03, 06:44 PM
Thanks man.
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.