代码之家  ›  专栏  ›  技术社区  ›  OM The Eternity

如何将主窗口从弹出窗口重定向到URL?

  •  3
  • OM The Eternity  · 技术社区  · 14 年前

    在弹出窗口中)。

    如何使用Javascript实现这一点?

    After Application of Josh Idea
    

    我调用一个javascript函数来提交一个表单,在这个javascript中,下面是提到的代码

    那么,这是否可以像我试着用这个来执行,而它却不能按我的需要工作呢

    function instant_popup_post()
    {
        var cid         = document.getElementById('product').value;
        var session_id  = document.getElementById('sessid').value;
        if(cid==30)
        {
            alert(document.getElementById('instantpop').onsubmit="opener.location.href = 'http://192.168.1.5/cppl11/bannerbuzznew/full_color_banner.php?&id=+cid+'&info_id=5&osCsid='+session_id;");
            document.instantpop.submit();   
        }
        else if(cid==31)
        {
            document.getElementById('instantpop').onsubmit="opener.location.href ='perforated_window_signs.php?&id='+cid+'&info_id=6&osCsid='+session_id;";
            document.instantpop.submit();   
        }
        else if(cid==32)
        {
            document.getElementById('instantpop').onsubmit="opener.location.href ='preprinted_stock_banner.php?&id='+cid+'&info_id=7&osCsid='+session_id;";
            document.instantpop.submit();
        }   
    }
    

    plss帮助

    2 回复  |  直到 14 年前
        1
  •  4
  •   Josh Stodola    14 年前

    在弹出窗口中,可以使用 opener 属性来引用父窗口。。。

    opener.location.href = 'http://www.google.com';
    

    你也可以调用父窗口上的函数。。。

    opener.functionName();
    

    当然,老好人 same origin policy 此处适用限制

        2
  •  0
  •   pjnovas    14 年前

    主窗口:

    function ShowModalForm()
    {
        var urlToRedirect = window.showModalDialog('url');
        if (urlToRedirect) 
           window.location = urlToRedirect;
    }
    

    function buttonAcceptClicked()
    {
        //Do stuff you need
        window.returnValue = "new url";
        window.close()
    }
    

    Here 有很多关于这个的信息。