带有自定义功能的 window.opener 在 Safari 中不起作用 [英] window.opener with a custom function does not work in Safari

查看:94
本文介绍了带有自定义功能的 window.opener 在 Safari 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am having an issue with Safari, specifically, not finding the window.opener function from the parent window. The function I'm calling works fine in Chrome and Firefox. Does anyone have any tips?

窗口 1(父)

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

Opens window 2 with the following:

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

窗口 2(弹出)

请求 url 页面返回后,调用以下内容:

After the request url page returns back, the following gets called:

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

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

I get the following error on the first line:

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

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

Note: I've tried a few variations of window.opener, parent.window.opener, and window.parent.opener.

窗口 1(父级)回调

原来打开弹窗的父窗口有下面的JS函数,但是一直没有到这个地步.

The original parent window that opened the popup has the following JS function, but it never gets to this point.

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

推荐答案

请将此视为评论.

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

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

inside a call to eval() makes a function in the argument string a property of the window. If the call back function is defined using eval() it could be a problem

这篇关于带有自定义功能的 window.opener 在 Safari 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆