...

View Full Version : Go to a specific page if a condition is not met



gijssr
08-26-2007, 04:47 PM
I would like to put coding in some of my pages so that depending on the previous page the visitor came from, he is send to a specific page.

I mean:
in page B.htm
if the previous page is not page A.htm got to page A.htm
else show page B.htm

ie. The only way to visit page B.htm is when you came from page A.htm

Anybody who can help me?
thanks

Philip M
08-26-2007, 05:15 PM
<head>
<script type = "text/javascript">
if (document.referrer.indexOf("http://www.yourURL.com") == -1) {
location.href = "http://www.yourURL.com/pageA.html";
}
</script>
</head>

gijssr
08-26-2007, 09:35 PM
Philip M,
This was exactly what I was looking for.

gijssr
08-26-2007, 10:40 PM
After testing:
Works fine with firefox
Microsoft Internet explorer sends you to page A.htm even when you come from page A.htm
Anybody any ideas

rwedge
08-26-2007, 11:18 PM
Try this on page B:
if (document.referrer.indexOf('pageA') == -1) {
location.replace('http://www.yourURL.com/pageA.html');
}

gijssr
08-27-2007, 02:21 PM
Thanks Rwedge,
but this coding has the same effect.
It looks like a bug? in the Internet Explorers Javascript interpreter:
The refering page (Page A)(to which I don't want to go back if I come from there) generates the destination page (page B) by a piece of javascript coding:
top.location=..............
Then after arriving at page B, document.referrer is empty.
even if I put a complete "url" after top.location= ;
in short:
document.referrer does not contain an address using Internet Explorer (coming from a page where top.location was the destination) while using Firefox it contains the correct url.

Any further ideas are very welcome.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum