views:

47

answers:

2

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

A: 

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.

Darkxes
Can U Show me Some Application of this stuff?
OM The Eternity
This will only work in IE
Josh Stodola
@OM The Eternity, the idea of the Modal popups is to stop the "parent thread" while it is opened, so if you have a form in your modal the parent execution will pause in the line window.showModalDialog until that modal is closed, after that it's gonna continue using the returned var.
Darkxes
@Josh I agree, that will only work with IE. @OM take that in concideration befor going into it hehe.
Darkxes
+1  A: 

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

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

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

opener.functionName();

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

Josh Stodola
Could u pls a bit more eloborative regarding window.opener, I canot fully understand the links u provided
OM The Eternity
@OM Just try something quick and dirty like `<form onsubmit="opener.location.href = 'http://www.google.com';">`
Josh Stodola