...

View Full Version : prompt referrer only for outside domain



dentaldude
10-25-2003, 08:27 PM
I want to modify the cofirm javascript prompt below to use as a disclaimer on my main page. but I'd like to modify it so that a person will see it when they come to the main page from another site outside my domain, www.whatever.com. So that if they are on another page within my domain and click to go to index.html, they will not see the prompt.

Thanks in advance for the help

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
var agree=confirm("I'd like to show you how to get this exact JavaScript message script. OK?");
if (agree)
document.write("");
else
history.go(-1);
// End -->
</SCRIPT>

Phip
10-26-2003, 01:13 AM
<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->
<!-- Begin
// http://coffeedemon.com/) = 24 chars
// http://www.coffeedemon.com/ = 28 chars

/********************************************
document.referrer gets the referrering address

substr(0,23)

this function will take a string like "http://coffeedemon.com/dir/dir/dir/dir/index.cd" and extract the first 23 charactors starting at 0 making it
"http://coffeedemon.com/"

document.refferrer.substr(0,23) replace the last charactor by the length of your site including "http://" and the ending "/" then subtract 1. do the same for
the second substr() but cound the length including "www." (add 4 to previous count) and subtract one.
*********************************************/

var agree=confirm("I'd like to show you how to get this exact JavaScript message script. OK?");

if(document.referrer.substr(0,23) == "http://coffeedemon.com/" !| document.referrer.substr(0,27) != "http://www.coffeedemon.com/")
{
if (agree)
{
document.write("");
}
else
{
history.go(-1);
}
}
// End -->
</SCRIPT>

Hope this helps

Willy Duitt
10-26-2003, 03:01 AM
If you have your own Domain you can try this.
It's best used if you use IP#'s eg: 216.32.421.12

If you can not use Server Side to store acceptance of the
Disclaimer. I would use cookies to store the info. Some sites do
not send a referrer, javascript could fail or stall, many things can
happen to kill or disable this script.

<script type="text/javascript">
<!--//

// Check if Referrer is within Domain. If so, stay on page
function goodUrl() {
a = location.href;
if (document.referrer.indexOf("http://www.whatever.com") > -1) {
a = a;
alert('Location.HREF='+a);
}
}
// Check if Referrer is within Domain. If no, choose OK or CANCEL
function badUrl() {
alert('Document.Referrer='+document.referrer);
if (document.referrer.indexOf("http://www.whatever.com") == -1){
agree = (confirm("You have come here from outside of the Domain.\nClick OK to proceed to our Main Entrance Page.\nClick CANCEL to return to wence you came from.") ? "yes" : "no")
}
// Check if Bad Referrer wishes to stay, If yes, GoTo Main Page
if (document.images && agree == "yes") {
location.replace("http://whatever.com/index.html")
}
// Check if Bad Referrer wishes to stay, If no, GoBack one page
if (document.images && agree == "no") {
history.go(-1);
}
}

function chkUrl() {
goodUrl();
badUrl();
}

window.onLoad=chkUrl();
//-->
</script>

Remove Alerts once you understand
how the script is running. :)

.....Willy

dentaldude
10-26-2003, 04:33 AM
Thanks guys - both unique ways of doing the same thing

If anyone else uses this, the script that Phip created has a typo in "if line" should be || not !| - but I have done that a thousand times myself :)

Willy Duitt
10-26-2003, 05:08 AM
I like Phip's better for its straightforwardness. :thumbsup:

But in defense of my lengthy example. It will redirect a user
to your index page if they enter your site thru a backdoor.

......Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum