INCLUDE_DATA

Volodymyr Osypov blog

December 25, 2008

Facebook hack - fb:prompt-permission onclick

Filed under: Facebook, JavaScript, Soft and Programming — Tags: , , , , , — admin @ 5:29 am

facebook As many of you know I work in i2we inc. and we create Facebook applications. Facebook has its own tags called FBML and own JavaScript library FBJS (all you JS-code is transferred into it, so there are some restrictions). There are also "extended permissions" - user can allow application to perform this or that action (change status, send emails and sms). User can be prompted for permission with <fb:prompt-permission> FBML tag, its required parameter is - perms, which has "extended permission" name in it, for example, "email" or "sms". It also may have optional "next_fbjs" parameter - FBJS function to run after user grants the extended permission. This prompt dialogue is called with <fb:prompt-permission> tag, text inside the tag becomes the link, when you click on it, dialog-box with 2 buttons: "Approve" and "Cancel" pops up.

We had a task to consider user completed the action even if he clicked Cancel on this dialog box, but we can't handle this situation as with next_fbjs. We decided to make an AJAX request when user clicks on dialog link, but this FBML tag doesn't have onclick. The solving was next - to put inside fb:prompt-permission <div> tag, and add to div-у onclick with the JavaScript function we need.

Here is the test example:

HTML:
  1. <input type="text" name="test" id="test" />
  2. </form>
  3.  
  4. <fb:prompt-permission perms="email"><div onclick="testjs();">Gimme permission</div></fb:prompt-permission>
  5.  
  6. <script type="text/javascript">
  7. function testjs() {
  8.      document.getElementById('test').setValue('Yes!');
  9.      //AJAX here
  10.      return false;
  11. }
  12. </script>

Powered by WordPress