Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

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,height=540");
GMWindow = window.open("", "GM", ",resizable=1,width=350,height=540");     //repeat for bug in some browsers
GMWindow.document.open();
GMWindow.document.writeln("<SCRIPT language=\"JavaScript\">");
GMWindow.document.writeln("document.write(\"You came from: \" + window.opener.location.href)");      //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>
0
georgedb
Asked:
georgedb
  • 2
1 Solution
 
Michel PlungjanIT ExpertCommented:
Firstly you are lucky that the script executes at all, the history.back loads another page before the script is done. At least use a setTimeout to allow the script to finish before you try to get the value of the previous page.

Secondly if your site is not where they came from, you will only be allowed to read the href in a sigend script in Netscape 4
This is a security thing to stop people from snooping.
You will have to live with the referrer


Lastly To have an opener where opener is not supported do a
WinID = window.open('','newwin);
if (!WinID.opener) WinID.opener = self;

Michel
0
 
georgedbAuthor Commented:
But why isn't the second <SCRIPT></SCRIPT> pair not visible in the source of the generated window? In what order does a browser load a page and execute code?

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
0
 
Michel PlungjanIT ExpertCommented:
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
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now