URL Referer not working on pop up windows

青春壹個敷衍的年華 提交于 2019-12-01 01:12:21
Cristian

My solution is to take it from "document.referrer"

document.addEventListener('DOMContentLoaded', function () {     
    document.getElementById('hfUrlReferrer').value = document.referrer; 
})
<a href="javascript:void(0);" onClick="MyWindow=window.open('','gallery','location=no,directories=no,menubar=no,scrollbars=no,width=550,height=550');MyWindow.location.href='yoururl.html;MyWindow.focus(); return false;">

The trick is to use location.href which does record the referer in IE.

I found this great workaround on a forum, and adapted it slightly.

Put this code at the top of your page:

<script language="JavaScript">
function goTo(url){
   var link = document.getElementById("link");
   link.href = url;
   link.click();
}
</script>
<a id="link" target="_blank" href="javascript:void(0)"
  style="visibility:hidden;position:absolute;"></a>

...and then build your links like this:

<input type="button" value=google onclick="goTo('http://www.google.com')">

What you're doing is creating an invisible <a> element, then using javascript to change that element's address, and programatically "click" it.

There's no easy answer to this - in general, the UrlReferrer is a browser-specific behaviour. Chrome, for instance, can process this differently than Internet Explorer.

If you are doing the referring yourself then you'll be best off passing a querystring parameter or using session state to identify the referring URL.

william

I'm not sure.. but I found out..

Session is not working if we call a new page using Javascripts.

I was told that all session values are reset on a new page which is called using javascripts.

As an alternative for my question, I used QueryString.

I really don't want the users to see the URL but I already hide the URL with javascript.

So, I have no problem using querystring, right?

Does anyone hava a better solution?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!