【发布时间】:2016-09-02 18:56:19
【问题描述】:
我正在使用以下 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?";
}
}
}
但在野生动物园中我得到了
TypeError: undefined is not an object (evaluating 'newWindow.focus')
我无法找到解决此问题的方法。有人可以帮忙吗?
【问题讨论】:
-
我不认为我可以,但是您是否通过控制台测试了您的 newWindow var?您是否使用参数最少的简单窗口进行了测试?看看这是否有所作为
-
试过还是一样
-
它实际上可能由于浏览器限制而失败:developer.mozilla.org/en-US/docs/Web/API/Window/focus
标签: javascript jquery html safari cross-browser