TypeError:undefined不是一个对象(评估'newWindow.focus') [英] TypeError: undefined is not an object (evaluating 'newWindow.focus')
问题描述
I am having the following javascript which open ups a child window with the sizes and align it int he center of the screen
我有以下的JavaScript,它打开一个窗口大小的子窗口, >函数PopupCenter(url,title,w,h){
//修正双屏幕位置大多数浏览器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) ;
//将注意力放在newWindow
if(window.focus){
newWindow.focus();
}
var timer = setInterval(checkChild,500);
函数checkChild(){
if(newWindow.closed){
var message ='您通过关闭窗口中止了交易!';
var status ='closed';
paymentResponseDisplay(消息,状态)
clearInterval(timer);
window.onbeforeunload = function(){
if(!newWindow.closed){
return你真的想放弃这个事务吗? ;
$ b $ / code>
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我得到
But in safari I am getting
TypeError: undefined is not an object (evaluating 'newWindow.focus')
我无法为此找到解决方法。有人可以帮忙吗?
I am unable to find a fix for this. Can some one help out?
推荐答案
在我的情况下,发生这个问题是因为我从Safari中的ajax结果调用了popup。
我收到了同步的ajax,它工作正常。
In my case, this problem occurred because I called popup from the ajax result in the Safari. I received ajax with sync and it worked fine.
这篇关于TypeError:undefined不是一个对象(评估'newWindow.focus')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!