How can I logout by Facebook JS-SDK? - javascript

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

Related

using fetch on mobile devices

I am quite new to Javascript and have googled this problem with no joy so was hoping someone could help me with this problem.
I am using fetch to grab a file to update my database.
It all works perfectly on desktops however it does not work at all on mobile.
Using alerts in my function I know it's the fetch not working, as an alert will fire if placed before the fetch but not when placed after.
I have included the polyfill in my code and still have no luck.
Here is my fetch code.
function dbPunch() {
console.log("function fired");
fetch('db-punch.php', {
method: 'GET'
}).then(function(response) {
console.log("fetch worked");
}).catch(function(err) {
console.log("fetch error");
alert("fetch error");
});
}
I have tried it in its simplest form and no luck there.
function dbPunch() {
console.log("function fired");
alert("clicked");
fetch('db-punch.php');
}
Can anyone see what I have done wrong? Thanks

Javascript function will not execute using Cookies

I made a javascript function and I am trying to execute it in the javascript area. However, it will not run. When I run the code it just does nothing. I am using Github, so if you want my full code, go to https://github.com/TheNumnut/Wars-of-Shares/blob/master/Login/index.html
I am trying to make a Login page for a game. I would rather use forms than prompts but I have not been able to do that. If somebody could tell me how to use forms I will greatly appreciate it.
This is my code:
function checkCookie(checkusername, checkpassword) {
if (getCookie("username") != "") {
setCookie("username", checkusername, 365);
setCookie("password", checkpassword, 365);
}
else {
if (checkusername != getCookie("username") {
alert("Username wrong");
}
else {
if (checkpassword != getCookie("password") {
alert("Password wrong");
}
}
}
window.open("https://thenumnut.github.io/Wars-of-Shares/", "_self");
}
checkCookie(prompt("Username"), prompt("Password: ");
Please have a look at my other code in Github, because it also has not been working. Especially the profile page. None of the clickable text and links have been working. The link to the Profile Page is https://github.com/TheNumnut/Wars-of-Shares/blob/master/Profile/index.html
Your JS code has syntax errors.
You're missing an extra ) in the 7th, 11th and 42th line.
You can press F12 on your browser and check the console tab, where javascript errors are displayed.
However, I need to agree with the other users that this login method is not a good practice and it's very easy to bypass.
JavaScript source is available to the user of any website. Since the JavaScript runs in the user's browser, the code has to be transferred to the user's browser so the browser knows what to do. This means I as the user can view the source. In this case, by viewing the source I can see the line:
window.open("https://thenumnut.github.io/Wars-of-Shares/", "_self");
So I can bypass your log in page just by looking at the page source and going straight to https://thenumnut.github.io/Wars-of-Shares/

Facebook logout onbeforeunload

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;
}

How to use JQuery and custom site variables with phantomjs

I'm trying out phantomjs for browser testing and am having a few issues. My current code is below...
var page = require('webpage').create();
page.open('http://address.com', function(){
console.log('page opened');
page.evaluate(function(){
console.log('inside page eval');
varname.varaction(13633);
})
if (jQuery('#bcx_13633_iframe_overlay').is(':visible')){
console.log('it is visible');
} else {
console.log('it is not visible');
}
console.log('made it to exit');
phantom.exit();
})
I've tried using includeJS with a link to jQuery and wrapping that around everything between page.open and phantom.exit but it seems to stall out and skip that portion. I have custom actions located on the site that I can call in the console if i visit it as called in the code listed above, however, it tells me that it can't find the variable name for that either. Anyone with phantomjs experience have any tips on how to fix this?

Embedding a SoundCloud recording right away?

Basically I want the user to record a sound with the SoundCloud recorder and once they click save, the sound they just recorded will be embedded on to my webpage.
I use the SC.record() method to get the recording. This is my function for where I save the recordings... Right now nothing is embedded when I try to run it
$('#save a').click(function(e) {
var currentURL ="";
e.preventDefault();
SC.connect({
connected: function() {
$('.status').html('Uploading...');
SC.recordUpload({
track: {
title: 'whatever',
sharing: 'public'
}
}, function(track) {
currentURL = '"'+track.permalink_url+'"';
$('#SCtracks').append('<li id='+currentURL+'>'+currentURL+'</li>');
SC.oEmbed(currentURL, {color: "ff0066"}, document.getElementById(currentURL));
});
}
});
});
But if I go in and call SC.oEmbed with a URL to a recording I made earlier it works fine.
So I think I might be trying to embed the recording before it is fully uploaded, but I don't know where else I could put that statement.
Thanks
This answered my question. I guess you have to just keep checking the state until it is for sure done. If someone know a quicker way please answer

Categories

Resources