georgedb
asked on
Referring URL even when user typed in my url or used bookmark
Hi,
I'm trying to display the URL the user came from. If he came with a link to my site, I can use the referrer value. But if he went to my site from his bookmarks / favourites list, this value is empty. The same when he typed in the location.
Is there a trick to achive the effect? See below what I try to do.... In words:
Onload of my (dummy) page, I generate a new window, put the opener window back one step and try to refer to the location of the window. See the errormessage I get within the comment tags within the HTML/JS below.
I tried several other things, like competely generate a page, including statements between <SCRIP></SCRIPT>, but that doesn't change much. Strange is that all JavaScript in the generated page is DISAPPEARED. So when I generate a page and write JavaScript to it, it's gone when I view the source of the generated window??????
I want this to work with all browsers that support JS. I understood that "window.opener" is not used in every JS capable browser. Is there an alternative?
----
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaSCript">
<!-- HIDE FROM OTHER BROWSERS
function showWindow() {
window.history.back(); //this window back one step to get lost of this dummy page
GMWindow = window.open("", "GM", ",resizable=1,width=350,he ight=540") ;
GMWindow = window.open("", "GM", ",resizable=1,width=350,he ight=540") ; //repeat for bug in some browsers
GMWindow.document.open();
GMWindow.document.writeln( "<SCRIPT language=\"JavaScript\">") ;
GMWindow.document.writeln( "document. write(\"Yo u came from: \" + window.opener.location.hre f)"); //where was the user before he typed in a new location or selected a bookmark?
GMWindow.document.writeln( "</SCRIPT> "); //if (s)he came from a link, than "referrer" contains the url
GMWindow.document.close();
}
// STOP HIDING FROM OTHER BROWSERS -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" onLoad="showWindow()">
<!-- this is just a dummy page
The error message I get is:
access disallowed from scripts at http://127.0.0.1/test.html to documents at another domain.
-->
</BODY>
</HTML>
I'm trying to display the URL the user came from. If he came with a link to my site, I can use the referrer value. But if he went to my site from his bookmarks / favourites list, this value is empty. The same when he typed in the location.
Is there a trick to achive the effect? See below what I try to do.... In words:
Onload of my (dummy) page, I generate a new window, put the opener window back one step and try to refer to the location of the window. See the errormessage I get within the comment tags within the HTML/JS below.
I tried several other things, like competely generate a page, including statements between <SCRIP></SCRIPT>, but that doesn't change much. Strange is that all JavaScript in the generated page is DISAPPEARED. So when I generate a page and write JavaScript to it, it's gone when I view the source of the generated window??????
I want this to work with all browsers that support JS. I understood that "window.opener" is not used in every JS capable browser. Is there an alternative?
----
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT LANGUAGE="JavaSCript">
<!-- HIDE FROM OTHER BROWSERS
function showWindow() {
window.history.back(); //this window back one step to get lost of this dummy page
GMWindow = window.open("", "GM", ",resizable=1,width=350,he
GMWindow = window.open("", "GM", ",resizable=1,width=350,he
GMWindow.document.open();
GMWindow.document.writeln(
GMWindow.document.writeln(
GMWindow.document.writeln(
GMWindow.document.close();
}
// STOP HIDING FROM OTHER BROWSERS -->
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" onLoad="showWindow()">
<!-- this is just a dummy page
The error message I get is:
access disallowed from scripts at http://127.0.0.1/test.html to documents at another domain.
-->
</BODY>
</HTML>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Netscape has lately (since 4.05?) taken to not show the script that generates the html - annoying but there you are - it is actually quite good for protecting scripts from casual copying...
The setTimeout will defer the execution - perhaps - it all comes down to scope - where does the script execute...
Yes it is a security thing, you can get around it with a signed script that allows UniversalBowserRead (Netscape only) but htat is a bit overdoing things...
Michel
The setTimeout will defer the execution - perhaps - it all comes down to scope - where does the script execute...
Yes it is a security thing, you can get around it with a signed script that allows UniversalBowserRead (Netscape only) but htat is a bit overdoing things...
Michel
ASKER
Your answer proposes the use of a setTimeout thing.... What exactly do you mean by that? Isn't it always that a page/script is completely loaded first before it's executed?
The answer is satisfactory, it's a real pain that referrer isn't filled with the url of the last page of the active browser window. I can imagine that it's a privacy thing that I can't get access to their whole historylist.....
Cheers,
George