JavaScript/Bookmarklets

Bookmarklets are one line scripts stored in the URL field of a bookmark. Bookmarklets have been around for a long time so they will work in older browsers.

JavaScript URI scheme
You should be familiar with URL that start with schemes like http and ftp, e.g. http://en.wikibooks.org/. There is also the JavaScript scheme, which is used to start every bookmarklet.

Media controls
The values in these examples can be adapted as desired. One may replace  with   where applicable, meaning where an   tag is embedded.


 * Loop the video

Can be switched off using  or.


 * Jump to ten minutes (using multiplication):


 * Jump forward by one minute (sixty seconds):


 * Jump back by half a minute (using division):


 * Get duration of a video on the page in console:


 * Alert the duration:


 * Alert the playback time:


 * Set audio volume to 50%:

Unmute using  or.
 * Mute audio


 * Double the playback speed:


 * Ask for playback speed:

is necessary to prevent setting the value to zero if the dialogue window is closed without user input.


 * Ask for playback position in seconds:


 * Ask for playback position in minutes:


 * Ask for playback position in percentage (0 to 100):

Using multiple lines of code
Since you cannot have line breaks in bookmarklets you must use a semicolon at the end of each code statement instead.

The JavaScript Protocol in Links
The JavaScript protocol can be used in links. This may be considered bad practice, as it prevents access for or confuses users who have disabled JavaScript. See ../Best Practices/.

Examples
A large quantity of links may be found on bookmarklets.com, which show a variety of features that can be performed within JavaScript.

JavaScript/Skryptozakładki