[英]Check for window.open support - JavaScript
I am working on fixing a bug regarding window.open
being triggered on mobile safari. 我正在修复有关在移动浏览器中触发的window.open
的错误。 Whenever this happens, an error is triggered as it seems window
is not defined or the function is not supported? 每当这种情况发生时,都会触发错误,因为似乎未定义window
或不支持该功能?
The approach I am considering taking is to check if window.open
is supported. 我正在考虑采用的方法是检查是否支持window.open
。 If so, open the window like normal. 如果是这样,请像平常一样打开窗口。 If not, simply redirect the page. 如果没有,只需重定向页面即可。 But how could I check for this support? 但是我如何检查这种支持?
if (window.open) {
var helpWindow = window.open('help.htm', 'DBHelp', 'width=800,height=600,left=100,top=100');
} else {
this.navigateTo('help.htm');
}
This is what I am trying, only with some dummy data in the URL for now. 这就是我正在尝试的方法,目前仅在URL中包含一些伪数据。 How could I best go about this? 我该怎么办呢?
Use window.open to open a random page and check for the body element. 使用window.open打开一个随机页面并检查body元素。 If it's there, then the page opened correctly, so window.open is supported. 如果在那里,则页面可以正确打开,因此支持window.open。
Edit: Even better, window.open will return null if the call failed. 编辑:更好的是,如果调用失败,window.open将返回null。
It sounds like window.open
is defined, but it's not able to open a new window. 听起来好像window.open
已定义,但是它无法打开新窗口。 So check the return value rather than the function name. 因此,请检查返回值而不是函数名称。
var helpWindow = window.open('help.htm', 'DBHelp', 'width=800,height=600,left=100,top=100');
if (!helpWindow) {
this.navigateTo('help.html');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.