[英]How to detect whether a browser supports window.close?
I'm building an app, where the auth flow goes as follows 我正在构建一个应用,身份验证流程如下
This flow works great on desktop devices, but not in mobile browsers, where window.open opens a new tab that can't be programmatically closed. 此流程在台式机设备上效果很好,但在移动浏览器中效果不佳,因为window.open会打开无法以编程方式关闭的新标签页。
On mobile devices, I can redirect the user to the login screen, and send them back with the auth token in the hash fragment (oauth2 implicit flow), but I only want to do that when I have to. 在移动设备上,我可以将用户重定向到登录屏幕,并使用哈希片段中的auth令牌(oauth2隐式流)将他们发送回去,但我只想在必须这样做时这样做。 How do I detect whether window.close works without browser sniffing?
如何检测window.close是否在没有浏览器嗅探的情况下工作?
I've tried using a HTML/JS based modal dialog with an iframe in it, but Google's login page doesn't allow embedding it in an iFrame, I haven't tried with other providers 我尝试使用基于HTML / JS的模式对话框以及iframe,但是Google的登录页面不允许将其嵌入iFrame,也没有尝试与其他提供程序一起使用
You can check if window.close()
is supported by object detection: 您可以检查对象检测是否支持
window.close()
:
if (window.close) {
alert ('window close is supported');
}
Do the check without paranthesis ()
, as you don't want to execute the function, but want to check for existance of the function/object. 进行不带paranthesis
()
的检查,因为您不想执行该功能,但是想要检查该功能/对象的存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.