Forum Moderators: open
I've tried a lot of different schemas I've found on the internet but keep running into an 'Access Denied' or 'Permission Denied' javascript error in the browser.
Basically, I get a lot of traffic from sites that open their link to my site in a new window, so there is no referrer information in the HTTP headers. My goal is to capture the URL in the parent window to identify where the visitor came from if the referrer is missing - does that make sense?
More importantly, is there a way to do this that I'm missing?
Thanks loads!
Anastasia
You need to make sure that you are opening the child window in an event, rather than as part of the href. For example:
<a href="tmp2.html" onclick="window.open('tmp2.html'); return false" title="Open Window">OPEN ME</a>
Then in your child window you can access the parent url like this:
<script type="text/javascript">document.write(window.opener.location.href);</script>
You can then do you checking by using an if conditional statement.
HTH
capture the URL in the parent window to identify where the visitor came from if the referrer is missing
That is not possible... You will not have access to that information unless the other site is on the same domain as yours. Furthermore, as BlobFisk said, window.opener doesn't work on regular links...
The referrer is your safest bet (though it cannot be trusted blindly).