Facebook logout onbeforeunload - javascript

In my AngularJS application I use the Facebook SDK.
When I use FB.logout() on the logout button click it works properly:
$scope.logout = function() {
FB.logout()
}
But I also want to logout from Facebook on window close. I do the following:
$window.onbeforeunload = function() {
FB.logout()
}
As you can see I do the same in both cases. However, second one does not work.
Could someone tell me, why? And how to make it work? Thanks!

You need to return null from onbeforeunload function. As mentioned here
So this should work.
$window.onbeforeunload = function() {
FB.logout()
return null;
}

Related

How can I close certificate authentication pop-up

Recently in our application we have added the Certification authentication and when ever we access the application the authentication pop-up is displayed and we have to select the correct authentication and click on the Ok button. I tried looking for solutions to use in protractor, but no luck. I have attached the SS of my window. When I use the below code I am getting only 1 windowhandler.
I would appreciate your help as my scripts failing due to this issue.
flow = protractor.promise.controlFlow();
flow.execute(function () {
browser.ignoreSynchronization = true;
browser.get('https://test.xyz.net/').then(function () {
browser.driver.getAllWindowHandles().then(function (handles) {
console.log (handles.length);
})
})
browser.ignoreSynchronization = false;
});

Redirect to login page once Refresh in Angularjs

I have developed an application in angular js with login authentication.
I have a requirement that, once user Refresh the page, application should redirect to login page.
How to achieve this ?
I tried with $location event i.e.
$locationChangeStart
But above event also gets fired when route of application changes.
Use window.onbeforeunload on .run method
myAPp.run(function ($rootScope, $location, $cookies) {
window.onbeforeunload = function (e) {
window.location.href = '/login';
}
});
You can do it by onbeforeunload,
window.onbeforeunload = function (e) {
window.location.href = '/login';
}
which should be triggered when either the back/forward/refresh buttons are clicked to perform an action, unfortunately you can't tell if they are going back or forward.

Close Window Javascript

Is there a way i can create a javascript which will run the command onClick="my_onclick()" if they close the browser window? If so can you also make a popup that warns them If they close the window it will log out on the same script?
I am trying some variations of what i found but its not working for me.
$(document).ready(function()
{
$(window).bind("beforeunload", function() {
return confirm("If you confirm, you will be logged off the internet.");
});
});
I need it to return these paramters.
function my_onclick()
{URL = "http://%SERVERIP%/logout?%PARAMS%"; window.location.href=URL;}
The only 'event' available within Javascript that relates to the closing of a window is onbeforeunload, which expects to return a boolean (from the result of calling window.confirm().
It cannot be used to pass data back, since the page will already have expired. In short, no you can't do that.
You can use window.onbeforeunload, here's an example of what you need:
window.onbeforeunload = myConfirm;
function myConfirm(){
confirmMessage="If you confirm, you will be logged off !!";
return confirmMessage;
}

KIll user session on window.onunload

I want to kill a users session if they back out of a certain page.
The problem is apparently window.onunload does not work in chrome or something to that effect. Is there a work around for this where I can kill the session ONLY when the user backs out ? Right now if the user backs out, it will give them a prompt which offers them the choice of staying on the page or leaving.
client side:
<a4j:jsFunction
name="killUserSession"
action="#{sessionController.invalidateSession()}"/>
...........
var warning = true;
window.onbeforeunload = function() {
if (warning) {
return "You have not filled out the required information below.";
}
}
window.onunload = function(){
killUserSession();
}
function setOnloadNull(){
console.log("Setting onload to null");
var warning = false;
window.onbeforeunload = null;
}
I check your issue and i found (under chrome) setOnLoadNull is the cause of the issue.
Demo fails.
But when i disable this method, then the onunload works like a charm.
Demo works.

How can I logout by Facebook JS-SDK?

I need to logout from Facebook from my application.
I tried to watch the other posts, but I didn't find what I need...
I have realised a link likeLOGOUT and I have written a function, but it doesn't work... I tried this 3 methods, but none of them works.
function FB_LOGOUT(){
//FB.logout(function(response) {
// window.location.reload(true);
//});
//FB.Event.subscribe('auth.logout', function(response) {
// window.location.reload();
//});
//FB.logout(function()
//{
// top.location.href = 'http://google.com/';
//});
}
Can you tell me how to logout from Facebook from my application? Please explain everything you think I'd better know, I'm really ignorant in this field... Thank you :)
Sorry I can't write as comment, try this
FB.logout(function(response) {
FB.Auth.setAuthResponse(null, 'unknown');
});
this refers to Facebook JS SDK FB.logout() doesn't terminate user session

Categories

Resources