gpt4 book ai didi

javascript - 类型错误 : undefined is not an object (evaluating 'newWindow.focus' )

转载 作者:行者123 更新时间:2023-11-28 06:03:21 29 4
gpt4 key购买 nike

我有以下 JavaScript,它打开一个具有尺寸的子窗口并将其对齐到屏幕中心

function PopupCenter(url, title, w, h) {
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;

var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}

var timer = setInterval(checkChild, 500);
function checkChild() {
if (newWindow.closed) {
var message = 'You have aborted the transaction by closing the window !';
var status = 'closed';
paymentResponseDisplay(message,status)
clearInterval(timer);
}
}
window.onbeforeunload = function() {
if(!newWindow.closed){
return "Do you really want to abort this transaction?";
}
}

}

但是在 safari 中我得到了

TypeError: undefined is not an object (evaluating 'newWindow.focus')

我无法找到解决此问题的方法。有人可以帮忙吗?

最佳答案

就我而言,出现这个问题是因为我在 Safari 中从 ajax 结果调用了 popup。我收到了带有同步的 ajax,它工作得很好。

window.open() works different on AJAX success

关于javascript - 类型错误 : undefined is not an object (evaluating 'newWindow.focus' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37093759/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com