Although the API provides a mechanism for detecting when the user clicks the Deny button, there is no built-in way to detect that the user has suddenly closed the pop-up window (or left his web browser, turned off his computer, and soon). The Deny condition is provided if you want to re-invite a user with limited areas (for example, you requested an "email", but you only need a profile and it will continue to work without providing you an email).
If the response from the login callback contains an access_denied error, it indicates that the user clicked the deny button:
function onSignInCallback(authResult) { if (authResult['error'] && authResult['error'] == 'access_denied') {
You should be able to embed the input without detecting whether the window was closed; This is demonstrated by almost all Google+ application examples . In short, you should avoid using a counter like you do, and instead hide the authenticated user interface until the user logs in.
It is not recommended to do this, but in order to implement pop-up close detection, you can do something like overriding the global call to window.open and then detect in window.unload or ask if the window was closed without user authentication:
var lastOpenedWindow = undefined; window.open = function (open) { return function (url, name, features) { // set name if missing here name = name || "default_window_name"; lastOpenedWindow = open.call(window, url, name, features); return lastOpenedWindow; }; }(window.open); var intervalHandle = undefined; function detectClose() { intervalHandle = setInterval(function(){ if (lastOpenedWindow && lastOpenedWindow.closed) { // TODO: check user was !authenticated console.log("Why did the window close without auth?"); window.clearInterval(intervalHandle); } }, 500); }
Please note that, as I implemented it, this mechanism is unreliable and depends on the conditions of the race.
class source share