window.opener with a custom function does not work in Safari

落爺英雄遲暮 提交于 2019-12-14 03:55:17

问题


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?

Window 1 (Parent)

Opens window 2 with the following:

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

Window 2 (Popup)

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")')

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

Window 1 (Parent) Callback

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");
}

回答1:


Edit: please treat this as comment.

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

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



来源:https://stackoverflow.com/questions/32639654/window-opener-with-a-custom-function-does-not-work-in-safari

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!