URL Referer not working on pop up windows

為{幸葍}努か 提交于 2019-11-30 21:12:45

问题


I have two pages namely www.abc.com/pg1.aspx and www.abc.com/pg2.aspx

pg1.aspx
response.redirect("www.abc.com/pg2.aspx");

pg2.aspx
string url_refer = Request.UrlReferrer.ToString();

UrlReferrer is working fine.

pg1.aspx
<a href='#' onclick=\"window.open('www.abc.com/pg2.aspx', 'windowname2', 'width=1014, height=709, screenX=1, left=1, screenY=1, top=1, status=no, menubar=no, resizable=no, toolbar=no'); return false;\">

pg2.aspx
string url_refer = Request.UrlReferrer.ToString();

UrlReferrer is NULL

I googled for the solution. but none of them are leading to the solution i want.

My problem is if the window is with no menubar, status or toolbar, UrlReferrer is NULL

if not, UrlReferrer has the previous page's URL.

I also tried url_refer = Request.ServerVariables["HTTP_REFERER"].ToString(); instead of string url_refer = Request.UrlReferrer.ToString();.

the result is the same.

Any solution?


回答1:


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

document.addEventListener('DOMContentLoaded', function () {     
    document.getElementById('hfUrlReferrer').value = document.referrer; 
})



回答2:


<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.




回答3:


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.




回答4:


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.




回答5:


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?



来源:https://stackoverflow.com/questions/7580613/url-referer-not-working-on-pop-up-windows

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