简体   繁体   中英

IE:how to get popup's opening window when using window.open(url)

we are running a click-to-call service, my idea is basically like this: website have a link on their page, when the link is clicked, a web page(say it is popup.aspx) hosted on our server is popup, user can input their phone number, and click "call me" button to let the website call him. In the button click event, I want to get Request.UrlReferrer, then query the db to get website's phone. But in IE, Request.UrlReferrer is null(firefox is ok, not test chrome yet),my question is how to get opening window' url in IE?

we put popup.aspx on our server because

  1. our client website is not force to use asp.net.

  2. we have the control what we put on the popup window, and can modify the page just from our side, if we put the pop window on our partner's side, if we have 100 partner, and we change the page's design, we will notify everyone of them to change this, change that...

  3. we can implement a statics system to know how popup a day, which site is most popular,etc

Did you try window.opener.location.href (in javascript)?

You could also call a pageMethod in javascript with the opener to get back your CSS from your (server side query) and apply it to your page in javascript.

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; using System.Collections.Generic; using 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)
    {

// Put your code to call your database here return "888-888-888"; } }

Calling page

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM