Skip to content

Use baker javascript events

Alessandro Morandi edited this page Oct 14, 2013 · 6 revisions

Baker supports some javascript events that are triggered when the page gets visualized on the screen and goes away, and when the user clicked on a URL that could not be handled.

Window Focus: the page is now visible

The focus event is fired when the page gets visualized on the screen. It's useful to trigger animations and event exactly when the user starts looking at the page.

The event behaves like the standard window focus function in standard browsers.

window.addEventListener("focus", function() { ... }, true);

Window Blur: the page is not visible anymore

The blur event is fired when the page goes off-screen and is not visible anymore. It's useful to disable animations, sounds and videos that might be playing in the background at the right moment.

The event behaves like the standard window blur function in standard browsers.

window.addEventListener("blur", function() { ... }, true);

URL not handled: an external app for the URL could not be found

It's possible to send messages to other installed iOS applications by crafting a special URL. For example, clicking the following link will open the Twitter app:

<a href="twitter://post?message=hello%20world">Share On Twitter</a>

The urlnothandled event is fired when such a link is clicked and the corresponding app is not installed on the device. The event has a url parameter.

window.addEventListener("urlnothandled", function(event) { alert(event.url) });

Info box initialization with user_id and app_id

Since Baker 4.2

Whenever the info.html page is loaded in the Info box, an init event is generated inside the page to pass in the current user_id and app_id (see Baker Server API for a description of the parameters).

The following example listens to the event and creates an alert popup with the values of the parameters.

window.addEventListener("init", function(event) { alert(event.user_id + " " + event.app_id) });
Clone this wiki locally