O'Reilly logo

Mastering jQuery by Alex Libby

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the API in a practical context

The API can be used in a variety of different contexts. The classic is usually to help control playback of video or audio, although it can be used with other APIs such as the Battery API, to prevent content being displayed at all if power levels are too low.

Let's take a moment to delve into some practical examples, so we can see how easy it is to implement the API.

Pausing video or audio

One of the most common uses of the API is to control playback of audio or media such as videos. In our first example, we're going to use the API to play or pause a video when switching between tabs. Let's delve in and take a look.

For this demo, we'll use a couple of additional items – the Dynamic Favicons library this is available ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required