Reputation: 12867
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.
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. How do I detect whether window.close works without browser sniffing?
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
Upvotes: 1
Views: 78
Reputation: 73251
You can check if window.close()
is supported by object detection:
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.
Upvotes: 1