The referring page can be accessed via document.referrer. This property will contain the address of the page that the user was on when they clicked a link that brought them to the current page. If they got to the current page using the back or forward buttons on the browser, it will contain the address of the page that they were on originally that linked them to the current page. If they get to the current page by typing its address into the browser or via a bookmark, the referrer is an empty string:
Code:
if (document.referrer!='http://www.somedomain.com/valid.htm')
window.location.replace('other.htm')
Something like the above should do the trick. Here is some actual code for a back button I wrote that determines if the user came from any other page on the current domain and to direct them back to it if they did, to a set page on the domain if they did not:
Code:
/*Intelligent Back button
* © John Davenport Scheuer (jscheuer1)
* as seen in www.dynamicdrive.forums
* this notice must remain for legal use */
function goBack(){
if(document.referrer.indexOf(location.hostname)==7)
history.go(-1);
else
window.location.href='main_1.htm';
}
Here is the markup:
HTML Code:
<a href="main_1.htm" onclick="goBack();return false;">
Bookmarks