2011-09-28 17 views
0

工作,我有兩個頁面分別www.abc.com/pg1.aspxwww.abc.com/pg2.aspxURL引用站點不是彈出窗口

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

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

UrlReferrer工作正常。

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(); 

UrlReferrerNULL

我GOOGLE的溶液。但他們都沒有導致我想要的解決方案。

我的問題是,如果窗口是沒有菜單欄,狀態或工具欄,UrlReferrerNULL

如果不是,UrlReferrer有以前的頁面的URL。我也試過url_refer = Request.ServerVariables["HTTP_REFERER"].ToString();而不是string url_refer = Request.UrlReferrer.ToString();

結果是一樣的。

任何解決方案?

回答

0

我不能肯定。但我發現..如果我們調用使用的Javascript了新的一頁

會話不工作。

有人告訴我,所有會話值都重置在使用javascripts調用的新頁面上。

作爲我的問題的替代方案,我使用了QueryString。

我真的希望用戶看到的URL,但我已經隱藏了JavaScript的URL。

所以,我沒有問題,使用querystring,儀式?

有沒有人有更好的解決方案?

0

有沒有簡單的答案 - 一般來說,UrlReferrer是一個瀏覽器特定的行爲。例如,Chrome可以以不同於Internet Explorer的方式進行處理。

如果您正在做自我介紹,那麼最好傳遞一個查詢字符串參數或使用會話狀態來標識引用的URL。

2

我的解決辦法是把它從「document.referrer」

document.addEventListener('DOMContentLoaded', function() {  
    document.getElementById('hfUrlReferrer').value = document.referrer; 
}) 
1
<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;"> 

訣竅是使用location.href它沒有記錄在IE的引薦。

1

我發現了這個很好的解決方法on a forum,並稍加修改。

把這段代碼在你的頁面的頂部:

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

...然後建立你的鏈接是這樣的:

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

你在做什麼是創造一種無形<a>元素,然後使用JavaScript來改變這種元素的地址,編程「點擊」它。