views:

224

answers:

2

I have some HTML that looks like this:

<a onclick="FB.Connect.logout(function() { window.location = '/'; });">
  link text
</a>

logout brings up a modal that tells the user he's logging out of Facebook and has "close" button on the bottom right. Unfortunately, the browser proceeds to '/' per the callback function. How can I stop that from happening so that the user has enough time to read what's in the dialog?

Also, the close button seems kind of useless since it gets blown away once the callback gets called, so I feel like I'm missing something there...

PS: This seems like a long shot, but I'd like the user to be able to stop the log out process if having to log out of fb changes his mind. Is there a way to do that?

A: 

Have you tried the pound sign? # This tells the browser to redirect to an in page anchor..and doesn't generally redirect anywhere. This might work for you!

Andrew Siemer
But the user is being led away by the window.location = '/'. I don't see how adding href="#" is going to stop that from happening.
allyourcode
window.location = '#' is what I was wondering about. Replace the / with a # and see what happens!
Andrew Siemer
but I want the user to be redirected to another page after he reads the dialog. I don't want the browser to just sit there.
allyourcode
A: 

If you're performing an action rather than going to a location, I'd recommend using a <button> element.

With Prototype:

<button id="button-logout" value="Logout" />

function finishLogout(isLoggedOut){
    if (isLoggedOut) {
      location.href = "/goodbye";
    }
}

function beginLogout(){
   //preparation if necessary.
   FB.Connect.logout(finishLogout); 
}

$('button-logout').observe('click', beginLogout);

It's always better to have your events in the javascript rather than inside your tag's onclick. And, although I did make two seperate functions, it's easier to revise and reuse them later, and you can always minify them if you're looking to optimize.

arbales
I'm already using the solution you suggest, but the problem is that when someone is running the site on their desktop, Facebook Connect might not be setup for them, and the beginLogout never gets called.
allyourcode

related questions