Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript and IE - document.referrer

Status
Not open for further replies.

steeleweed

Programmer
May 11, 1999
4
US
I have a page that is password-entered...I want to make sure viewers get there via the password page.<br>
Checking document.referrer works fine for NS but is unrecognized for IE4 and IE5. I could test for IE and<br>
execute different code if I knew what that code should consist of. Anybody know how to make javascript <br>
recognoze URL which was linked from?<br>

 
has 'index.html' which carries<br>
the META tags for search engines on an entry screen.<br>
After a few seconds, control passes to 'pass.html'. This<br>
has no HTML code, only Javascript but it is considered a 'document' by a browser. This page prompts for and validates a password. If correct password is entered, control will<br>
pass to 'first.html'. All this works fine. I added some<br>
Javascript to 'first.html' to require that the page be<br>
entered via 'pass.html'....code set a variable to value of<br>
'document.referrer' and compared the variable to 'pass.html'<br>
which worked with NS: if I entered via 'pass.html' I was<br>
allowed in...if I went directly to 'first.html' I was <br>
rejected, just as intended. Problem is that IE (all<br>
verions) does not recognize 'document.referrer', so I'm <br>
always rejected when attempting access via IE. Need to <br>
find out if/how IE refers to name of previous URL.<br>
 
Here's a quick trick that should solve your problem here:<br>
<br>
In the pass.html where you normally have it forward verified passwords to first.html, insert this script:<br>
<br>
window.open("entrance.ref();<br>
<br>
and in your first.html page insert the following script:<br>
<br>
Oops, sorry, out of time.....I'll finish this message in a couple of hours.
 
OK, here's the script to add to your first.html page, please let me know if these work:<br>
<br>
var safety=settimeout("window.location.history.back();",1000);<br>
function ref(){cleartimeout(safety)};<br>
<br>
What this SHOULD do (if it doesn't develop any bugs):<br>
<br>
<br>
When you enter through the password page:<br>
Another browser window will be opened containing the first.html page and everything should be fine.<br>
<br>
When you enter from somewhere else:<br>
You will see the first.html page for about 1 second, then your browser (as long as it's a version 3.0 or higher) will automatically take you BACK to the last page you were at, wherever that happens to be.
 
Please let me know if the script I gave you worked; if not, I would like to know so that I may work to correct it.<br>
<br>
<br>
-Robherc
 
<br>
I fixed the problem. 'pass.html' had no HTML code, only the<br>
javascript that obtained and verified the password, then <br>
passed control to 'first.html'. When 'first.html' tested <br>
'document.referrer', NS yielded 'pass.html' but IE gave <br>
nothing. Completely on a hunch (I've been around computers <br>
since Moby Dick was a minnow), I inserted an intermediate page, with 'pass.html' going to 'extra.html' and from there a Link to 'first.html', which verifies that<br>
document.referrer == "extra.html".<br>
This works. I guess IE requires genuine HTML code in order <br>
to set a non-blank value to document.referrer. Another <br>
oddity did pop up: originally, I had 'extra.html' coded<br>
&lt;meta http-equiv="Refresh" content="2;URL=http://....first.html"&gt;<br>
For some reason, the Refresh fails..sort of...it takes me<br>
back to the page last previous genuine HTML page, that <br>
which preceeded 'pass.html'. I gave up and let user <br>
click the link from 'extra' to 'first'. <br>
Thanks for checking back...<br>
Ray Saunders<br>
<br>

 
Quick tip to help with that one little glich:<br>
<br>
insert the following clause in your &lt;body&gt; tag to have JavaScript automatically forward NS users (sorry, doesn't work with IE) to the first.htm page w/o their having to click on a link (IE users still have to use the link if you do this one):<br>
<br>
onLoad="if(window.location.href){window.location.href=<br>
This will automatically forward all users who have a browser that supports the property: window.location.href (that means NS 3.0 & higher) to the first.htm page while doing ABSOLUTELY NOTHING in browsers that don't support this. It's a quick way to make a few of your users happier, so I think it's well worth it.<br>
<br>
<br>
-Robherc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top