2010-09-23 106 views
1

獲取彈出窗口的打開窗口我們正在運行一個點擊通話服務,我的想法基本上是這樣的:網站在他們的頁面上有一個鏈接,當鏈接被點擊時,在我們的服務器上託管的一個網頁(稱爲popup.aspx)是彈出式的,用戶可以輸入他們的電話號碼,並點擊「打電話給我」按鈕讓網站給他打電話。在按鈕點擊事件中,我想獲取Request.UrlReferrer,然後查詢數據庫以獲取網站的電話。但在IE瀏覽器中,Request.UrlReferrer爲null(firefox沒問題,還沒有測試Chrome),我的問題是如何在IE中打開窗口的url?IE瀏覽器:如何使用window.open(url)

我們把我們的服務器上popup.aspx因爲

  1. 我們的客戶的網站沒有強制使用asp.net。

  2. 我們可以控制我們在彈出窗口中放置的內容,並且可以從我們這邊修改頁面,如果我們將彈出窗口放在合作伙伴的一側,如果我們有100個合作伙伴,並且我們更改頁面的設計,我們會通知他們每個人都進行更改,更改...

  3. 我們可以實現一個靜態系統,知道如何彈出一個日子,這網站是最流行的,等

回答

1

你有沒有嘗試window.opener.location.href(在JavaScript中)?

您也可以在開頭器中用javascript調用pageMethod以從您的(服務器端查詢)取回CSS並將其應用到您的頁面。

Link

Popup.aspx

<form id="form1" runat="server"> 
<asp:ScriptManager EnablePageMethods="true" runat="server"></asp:ScriptManager> 
<div> 

<script> 
    function call() { 
     var location = window.opener.location.href;  
     PageMethods.GetPhoneNumber(location, clientcall); 
    } 

    function clientcall(phone){ 
     alert(phone); 
    } 

</script> 
<a href="javascript:call();">Call</a> 
</div> 
</form> 

Popup.aspx.cs

使用系統; using System.Collections.Generic;使用System.Linq的 ; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.Services;

public partial class Popup : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 

    [WebMethod] 
    public static string GetPhoneNumber(string referer) 
    { 

//把你的代碼中調用此數據庫 回報 「888-888-888」; }}

調用頁面

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <title></title> 
</head> 
<body> 
<script> 
    function opening() { 
     window.open("Popup.aspx","mywindow", "status=1,toolbar=1"); 
    } 
</script> 
<a href="#" onclick="opening()">Ouvrir</a> 

</body> 
</html> 
相關問題