Click to See Complete Forum and Search --> : Document.Referrer Help...


kwilliams
11-10-2003, 01:40 PM
Hi,

I tried using the JS document.referrer method to pull our intranet user's last page, but it doesn't work. We moved our intranet site from an old server to a new one, and I want to redirect user's to the new version of their requested page by using JS.

I read some lit that said document.referrer would only work from a link, not a redirect. So I tested that out, and it did work. But I want the user to be redirected to my redirect page, which will pull in the URL with the old server name, and forward them to the new version of the URL with the new server name. This is what I came up with:
<script language="JavaScript">
<!--Pull previous URL, and redirects from old server to new one
//Pull Previous URL
var url = document.referrer;//Pull in page
//Split URL
var oldurl = url.split("http://OLDSERVERNAME");//use split method to pull page info, no matter
var pageinfo = oldurl[1];
//Attach old URL to new server name
var newurl = ("http://NEWSERVERNAME" + pageinfo);
//Redirect to new version of URL
//location.href
document.write(newurl);
//-->
</script>

It does work when the user clicks a link, but can anyone see how I can have the referrer page do some kind of onLoad event that will act as a clicked link? This is what I thought of:

<script language="JavaScript">
function redirect() {
location.href="http://dgitsrv1/redirect.asp";}
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000" onLoad="redirect()">

...but it just resulted in a redirect, and not a clicked link. Any suggestions, including another way around this would be appreciated!!!

KWilliams

gil davis
11-10-2003, 02:05 PM
You can try putting a real link in the page and then invoke the click method on that link:

<a id="l1" href="newpageurl"></a>
<script>
document.getElementById("l1").click();
</script>
untested.

kwilliams
11-10-2003, 02:14 PM
IT WORKED! This is the code I used from your original code:

<a id="1" href="redirect.asp">redirect</a>
<script>
document.getElementById("1").click();
</script>

...and it did pull the referring page. Thanks so much for the quick response Gil!!!

KWilliams