2017-05-03 80 views
1

基本上,我有一个页面,其中包含一个javascript文件。在js文件 我有两个功能称为功能a()和功能b()。内函数“A”我调用弹出来加载。加载子弹出后,我有一个称为交互的函数,它会调用ajax。如果结果为真,我需要关闭子页面,然后在主页面中调用函数“B”。下面是示例代码。问题是我不能在子页面中引用函数“B”并调用主页面。关闭子页后刷新主页

function a() { 
    var strWindowFeatures = "location=yes,scrollbars=yes,status=yes"; 
    var URL = path of the url 
    var win = window.open(URL, "_blank", strWindowFeatures); 
} 

function b() { 
    calling a 
    function to relaod the page. // 
} 


function InterActive(encodeText) { 

    url: url 
    cache: false, 
    async: false, 
    type: 'GET', 
    contentType: 'application/json; charset=utf-8', 
    data: {}, 
    dataType: 'json', 
    success: function (data) { 
     if (data === true) { 
      alert('record updated'); 
      window.close(); 
      // i need to call the function b() in the child page.. 

     } 
    }, 
    error: function (jqXHR, textStatus, errorThrown) { 
     alert(jqXHR); 
     alert(textStatus); 
     alert(errorThrown); 
    } 
}); 
+0

所以你打开一个新窗口? –

+0

是的。在关闭弹出窗口之前的子窗口中,我需要调用主窗口中的函数 –

+0

为子窗口添加一个'onbeforeunload'事件处理程序,用于调用重载功能 – Icepickle

回答

0

您可以在打开的窗口接收到一个onbeforeunload事件调用父窗口的装载功能,这样的方式做到这一点。

一个例子是以下

function reloader() { 
    if (!reloader.id) { 
    reloader.id = 0; 
    } 
    document.querySelector('#reloadCount').innerHTML = ++reloader.id; 
} 

function openWindow() { 
    var win = window.open('about:blank', 'blank', 'width=640,height=480'); 
    win.document.write('<html><head><body><h1>Reloads on close</h1></body></html>'); 
    win.addEventListener('beforeunload', function() { 
    reloader(); 
    return true; 
    }); 
} 

,你可以在jsfiddle here测试(window.open不允许在stacksnippets)

+0

不可以。主窗口函数没有被调用 –

+0

addEventListener在IE中出错 –

+0

@jaiganesh你可以更具体的IE版本,对于我在Chrome,Firefox和Internet Explorer中的示例工程(IE显示给我一个确认对话框,但是它更新重新加载的部分) – Icepickle

-1

我认为你需要在孩子添加函数B()页面,所以很容易访问,所以请检查这一点。

+0

这对OP有何帮助? – Icepickle