2010-09-30 134 views
3

我有一个窗体的弹出式窗口。在提交表单时,我希望重定向到特定页面,但在父窗口上(弹出窗口上的而不是)。如何将主窗口从弹出窗口重定向到URL?

我怎样才能实现这个使用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帮助

+0

我已经解决了它乔希谢谢你再次 – 2010-10-05 13:07:07

+0

@OM欢迎您! – 2010-10-05 21:34:04

回答

4

从弹出内,您可以使用opener属性引用父窗口...

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

您也可以调用父窗口的功能...

opener.functionName(); 

中当然,好老same origin policy限制适用于这里

+0

你可以稍微多说一点关于window.opener,我完全理解你提供的链接 – 2010-09-30 14:37:06

+0

@OM只是尝试一些快速和肮脏的像

' – 2010-09-30 14:47:22

0

我会说使用的showModalDialog,所以你会冻结的父窗口,并完成后,可以将变量发送到家长和做重定向:

主窗口:

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是很多的这方面的信息。

+0

你能告诉我一些应用这个东西吗? – 2010-09-30 14:13:56

+0

这只适用于IE – 2010-09-30 14:15:50

+0

@OM永恒,Modal弹出窗口的想法是在打开时停止“父线程”,所以如果在模态中有一个窗体,父窗口的执行将在窗口中暂停.showModalDialog直到该模式被关闭,之后它将继续使用返回的变量。 – pjnovas 2010-09-30 14:44:46

相关问题