954,600 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

"Must visit from" javascript wont work in IE...

I have obtained the following script which only lets a page load if the visitor has been to the previous page, if they haven’t it sends the visitor to the appropriate page. However, it only works in Mozilla. Can anyone help me adapt this script to work in Internet Explorer?

<SCRIPT LANGUAGE="JavaScript" > 
<!-- Begin
var requiredfrom = "http://domain.com/somepage.htm"; //  required prev. page
if (document.referrer.indexOf(requiredfrom) == -1) {
alert("You must logon first...");
window.location=requiredfrom;
}
//  End --> 
</script>

Cheers,
NuGG

NuGG
Junior Poster
111 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

If you need an example of this script in action click here.

P.S. When I try this script in IE I receve the "must logon first" error regardless of visiting the previous page or not.

NuGG
Junior Poster
111 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

I'm using Internet Explorer and it worked for me!

cscgal
The Queen of DaniWeb
Administrator
19,437 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 231
 

How odd. What version of IE are you using? I've tried it on multiple computers with IE 6.0 and it didnt work on any of them...

NuGG
Junior Poster
111 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

Does this javascript work in IE for anyone else?

I'm using Internet Explorer and it worked for me!


Its quite odd that it didnt work for me in IE but it works for you. Could it be something to do with the history settings in IE, or would that not make any difference?

The script works perfectly every time in firefox so i dont understand why it shouldnt work in IE.

NuGG
Junior Poster
111 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

document.referrer may contain the address of the previous page or it may not. There are a number of factors that can affect this such as browser settings, firewall settings, IE also suppresses the value if the prior page was on a secure server, etc. If this happens then you have no way to tell what page your visotir was on previous to coming to your page.

felgall
Junior Poster in Training
50 posts since Aug 2004
Reputation Points: 13
Solved Threads: 1
 

...but it did work for me, IE and FireFox.

tgreer
Made Her Cry
Team Colleague
2,118 posts since Dec 2004
Reputation Points: 227
Solved Threads: 37
 

You have successfully logged on... Click here to continue.

Note: I take no responsibility for your presence on this site during school. You are here out of your own free will, and if you get your internet and email restricted its your own fault.

Then when I clicked the word "here" I got the you must log on message in a popup.

Bomba
Light Poster
33 posts since Oct 2005
Reputation Points: 10
Solved Threads: 1
 

Whether the script works or not can depend on the browser and firewall settings on individual computers. That would be the reason some people say it works and others say it doesn't. You can't rely on document.referrer containing anything as there are too many different ways it can be turned off.

felgall
Junior Poster in Training
50 posts since Aug 2004
Reputation Points: 13
Solved Threads: 1
 

Ok Im going to forget that idea then. Thanks for your help.

NuGG
Junior Poster
111 posts since Feb 2005
Reputation Points: 10
Solved Threads: 1
 

A client side solution means the client has to load the page first, you absolutely need a server side solution.
PHP session variables I think would be the way to go, when a page is requested, your PHP on the server would determine what was served up to the requestor.
I have not used PHP sessions yet so I could not explain it's use, but have been reading about it so I can implement it in the near future.
Here are some links that might help:
http://us.php.net/manual/en/ref.session.php
http://www.sitepoint.com/article/users-php-sessions-mysql

HazardTW
Junior Poster in Training
71 posts since Sep 2007
Reputation Points: 37
Solved Threads: 3
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You