Helpful Information
 
 
Category: JavaScript programming
access to pages

I am looking for a script that will only let a user access a certain page if they came FROM a designated other page. Is that possible?

Thanks!

hi,

don't have a sample for your right now, but what you're looking
for is the window.referrer function.

Thanks! Does anyone else out there possibly have a coding example for me?

Keep in mind that It's not totally reliable - for instance it won't work if they access your page directly (from a bookmark, for example), since there will not be a referrer in that case. However, you did ask for an example!:

<script language="JavaScript" type="text/javascript">
<!--
var thereferrer = document.referrer;
if(thereferrer != "http://www.mysite.com/myreferringpage.html"){
window.location = "http://www.barbie.com";
}
// -->
</script>

If you're not sure what the document.referrer IS, you can type this in the address bar (it should even work right here, right now...)!

javascript:alert(document.referrer)

:)

Thanks so much! I will give it a try tomorrow!:D










privacy (GDPR)