【问题标题】:window.opener with a custom function does not work in Safari具有自定义功能的 window.opener 在 Safari 中不起作用
【发布时间】:2015-09-17 20:44:32
【问题描述】:

我在使用 Safari 时遇到问题,特别是在父窗口中找不到 window.opener 函数。我调用的函数在 Chrome 和 Firefox 中运行良好。有人有什么建议吗?

窗口 1(父)

使用以下内容打开窗口 2:

window.open(requestUrl, "_blank", "width=440, height=500, scrollbars");

窗口 2(弹出窗口)

请求url页面返回后,调用如下:

window.parent.opener.callBackIntegrationCompleted("testing");
window.close();

我在第一行收到以下错误:

TypeError: undefined is not a function (evaluating 'window.parent.opener.callBackIntegrationCompleted("testing")')

注意:我尝试了 window.opener、parent.window.opener 和 window.parent.opener 的一些变体。

窗口 1(父)回调

原来打开弹窗的父窗口有如下JS函数,但是一直到不了这个地步。

function callBackIntegrationCompleted(code) {
    console.log("got here");
}

【问题讨论】:

    标签: javascript safari window.open window.opener


    【解决方案1】:

    编辑:请将此视为评论。

    function callBackIntegrationCompleted(code) {
        console.log("got here");
    }
    window.callBackIntegrationCompleted = callBackIntegrationCompleted;
    

    在对 eval() 的调用中,使参数字符串中的函数成为窗口的属性。如果回调函数是使用 eval() 定义的,这可能是个问题

    【讨论】:

    • 太棒了! window.callBackIntegrationCompleted = callBackIntegrationCompleted;正是我所需要的。
    猜你喜欢
    • 2022-06-13
    • 2018-04-04
    • 2021-12-22
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    • 1970-01-01
    相关资源
    最近更新 更多