Facebook Developers
DocsToolsSupportNewsApps
Log In
  • Social Plugins
  • Facebook Login
  • Open Graph
  • Facebook APIs
  • Games
  • Payments
  • App Center
  • Promote Your App
  • iOS
  • Android
  • JavaScript
    • Getting Started
    • How-Tos
    • Reference
  • PHP
  • More SDKs
  • Core Methods
    • FB.api
    • FB.init
    • FB.ui
  • Auth Methods
    • FB.getAuthResponse
    • FB.getLoginStatus
    • FB.login
    • FB.logout
  • Event Handling
    • FB.Event.subscribe
    • FB.Event.unsubscribe
  • XFBML
    • FB.XFBML.parse
  • Canvas Methods
    • FB.Canvas.Prefetcher.addStaticResource
    • FB.Canvas.Prefetcher.setCollectionMode
    • FB.Canvas.hideFlashElement
    • FB.Canvas.scrollTo
    • FB.Canvas.setAutoGrow
    • FB.Canvas.setDoneLoading
    • FB.Canvas.setSize
    • FB.Canvas.setUrlHandler
    • FB.Canvas.showFlashElement
    • FB.Canvas.startTimer
    • FB.Canvas.stopTimer

FB.Canvas.setUrlHandler

JavaScript › Reference › FB.Canvas.setUrlHandler

Overview

Registers the callback for inline processing (i.e. without page reload) of user actions when they click on any link to the current app from Canvas, including:

  • All ticker stories
  • Bookmarks
  • Requests from the bookmarks drop-down list
  • Request Notifications stories.

When user clicks on a ticker story for example, by default we would redirect the user to the corresponding URL. The app can choose to instead register a callback to display the achievement within the application.

Callback will be called with a field that contains the path of the URL, relative to you application's canvas URL; for example, if the URL that would have been loaded was http://apps.facebook.com/yourgameXYZ/achievements/cheevo1.php?fb_source=canvas_ticker&fb_ticker_mod=achievement&fb_action_types=games.achieves, callback will be called with parameter

{
    path: "/achievements/cheevo1.php?fb_source=canvas_ticker&fb_ticker_mod=
      achievement&fb_action_types=games.achieves"
}

Example

 function onUrl(data) {
     if (data.path.indexOf("games.achieves") != -1) {
         console.log('I will process some achievement now.');
     } else if (data.path.indexOf("request_ids") != -1) {
         console.log('I will process some request now.');
     } else {
         // default behaviour
         window.location = data.path;
     }
 } 

 FB.Canvas.setUrlHandler(onUrl);

Note

Each call to FB.Canvas.setUrlHandler() invalidates previously set callback, if any.

Only links pointing to canvas page (i.e. starting with apps.facebook.com/your_app/) will be sent for inline processing.

Return

NameTypeDescription
path string path to the achievement, relative to you application's canvas URL

Parameters

NameTypeDescription
callbackFunction

Callback function taking one argument, as described above.

Updated about 2 weeks ago
Facebook © 2013 · English (US)
AboutAdvertisingCareersPlatform PoliciesPrivacy Policy