【问题标题】:After opening popup, How do I redirect parent page?打开弹出窗口后,如何重定向父页面?
【发布时间】:2014-02-23 06:14:31
【问题描述】:

在 ASP.net 和 C# 中 - 在我的 pageLoad 事件中,我单击了一个按钮,该按钮已编写代码以获取 SSO 链接,然后使用 RegisterStartUpScript 添加一个 window.open,其中包含指向 SSO 的链接.

SSO 打开并加载后,我想将带有 pageLoad 事件的页面重定向到另一个页面。

在下面的代码中,autoOpenSSO 和 redirectUser 是在管理 UI 中加载的设置。

问题:当 autoOpenSSO 为 true 并且我将 redirectUser 设置为 false 时,弹出窗口会毫无问题地打开,但是当我将重定向设置为 true 时,弹出窗口不会打开,并且页面会重定向回我的重定向地址.

我希望弹出窗口打开并将页面重定向回我的重定向页面,但感觉我错过了一些东西,并且没有任何运气搜索。

我的代码:

protected void Page_Load(object sender, EventArgs e)
    {        
       if (autoOpenSSO == true)
       {
           ccdetails_Click(this, null);
       }


     if (redirectUser == true)
       {               
        Response.Redirect(redirectAddress);               
       }


    }

    protected void ccdetails_Click(object sender, EventArgs e)
    {
        ClientScriptManager cs = Page.ClientScript;
        try
        {  
            string link = getSSOlink(ah1.InstitutionUserID, cardnumber).Trim();
            string s = "window.open('" + link + "','_blank', 'width=980,height=600,resizable=yes');";
            cs.RegisterStartupScript(this.GetType(), "PopupScript", s, true);

        }

        catch (Exception se)
        {
           LogSystem.LogInfo(se.ToString());

        }
    }

感谢任何想法。

【问题讨论】:

  • 需要为弹窗添加EventListener。
  • 感谢@Anon 的关键字。我尝试添加 var popupWindow = window.open('" + link + "','_blank', 'width=980,height=600,resizable=yes'); if (popupWindow) { popupWindow.onload = function() {window.location.replace('" + redirectAddress +"') };},但是因为它是跨域的,我不认为我的JS可以得到做这个功能当 window.onLoad 会触发。我正在考虑设置一个超时来修复它。
  • 好吧,为了我的需要,我只是确定我不需要听众或任何东西。我只是在我的启动脚本中添加了重定向语言,而不是在 C# 中。如果需要,我将进行一个添加脚本的设置,如果没有,它将保留在页面上而不是重定向。我稍后会添加代码。

标签: c# javascript asp.net redirect


【解决方案1】:

我所要做的就是在我的注册启动脚本中添加另一行 js,以重定向到我想要的页面。修改后的代码可以在下面找到。我的页面上有设置允许我决定是否要自动打开 SSO 并在 SSO 打开后自动重定向用户,这是 s=s+t 部分的用途。

protected void Page_Load(object sender, EventArgs e)
    {         

       if (autoOpenSSO == true)
       {
           ccdetails_Click(this, null);
       }

    }

    protected void ccdetails_Click(object sender, EventArgs e)
    {
        ClientScriptManager cs = Page.ClientScript;
        try
        {                
            string link = getSSOlink(ah1.InstitutionUserID, cardnumber).Trim();
            string s = "var popupWindow = window.open('" + link + "','_blank', 'width=980,height=600,resizable=yes');";
            string t = "window.location.replace('" + redirectAddress + "')";
            if (redirectUser == true)
            {
                s = s + t;
            }
            cs.RegisterStartupScript(this.GetType(), "PopupScript", s, true);

        }

        catch (Exception se)
        {
            LogSystem.LogInfo("Access issue - " + se.ToString());

        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-18
    • 1970-01-01
    • 2012-06-03
    • 2023-03-06
    • 1970-01-01
    • 2011-07-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多