The method FB.Canvas.setUrlHandler()
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:
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"
}
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);
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.
Name | Type | Description |
---|---|---|
path |
| Path to the achievement, relative to you application's canvas URL |
Name | Type | Required | Description |
---|---|---|---|
callback |
| no | Callback function taking one argument, as described above. |