最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to redirect main window to URL from popup? - Stack Overflow

programmeradmin1浏览0评论

I have a pop-up window with a form in it. On submit of the form, I wish to redirect to a particular page, but on the parent window (not on the popup).

How can I achieve this using Javascript?

After Application of Josh Idea

I am calling a javascript function to submit a form, in this javascript, below is the mentioned code

So Can this be executed as i tried with this and its not working as per my need

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 help

I have a pop-up window with a form in it. On submit of the form, I wish to redirect to a particular page, but on the parent window (not on the popup).

How can I achieve this using Javascript?

After Application of Josh Idea

I am calling a javascript function to submit a form, in this javascript, below is the mentioned code

So Can this be executed as i tried with this and its not working as per my need

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 help

Share Improve this question edited Oct 5, 2010 at 12:30 OM The Eternity asked Sep 30, 2010 at 13:50 OM The EternityOM The Eternity 16.2k44 gold badges125 silver badges187 bronze badges 1
  • I reolved It Josh Thanks To u again – OM The Eternity Commented Oct 5, 2010 at 13:07
Add a ment  | 

2 Answers 2

Reset to default 4

From within the popup, you can use the opener property to reference the parent window...

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

You can also invoke functions on the parent window...

opener.functionName();

Of course, the good old same origin policy restrictions apply here

I would say to use showModalDialog, so you will be freezing the parent window, and after it is done, you can send a variable to parent and do the redirect:

MainWindow:

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

Popup Window:

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

Here is a lot of information about this.

发布评论

评论列表(0)

  1. 暂无评论