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.
You should be familiar with URL that start with schemes likehttp andftp, e.g. http://en.wikibooks.org/. There is also theJavaScript scheme, which is used to start every bookmarklet.
JavaScript:alert('Hello, World!');
The values in these examples can be adapted as desired. One may replacevideo withaudio where applicable, meaning where an<audio> tag is embedded.
javascript:document.getElementsByTagName("video")[0].loop=1;javascript:document.getElementsByTagName("video")[0].loop=true;// also works
Can be switched off using0 orfalse.
javascript:document.getElementsByTagName("video")[0].currentTime=60*10;
javascript:document.getElementsByTagName("video")[0].currentTime+=60;
javascript:document.getElementsByTagName("video")[0].currentTime-=60/2;
javascript:document.getElementsByTagName("video")[0].duration
javascript:alert('This video is '+document.getElementsByTagName("video")[0].duration+' seconds long.')
javascript:alert('The current position of the video is at '+document.getElementsByTagName("video")[0].currentTime+' seconds.')
javascript:document.getElementsByTagName("video")[0].volume=50/100
javascript:document.getElementsByTagName("video")[0].muted=1// "true" works as well
Unmute using0 orfalse.
javascript:document.getElementsByTagName("video")[0].playbackRate=2
javascript:document.getElementsByTagName("video")[0].playbackRate=parseFloat(prompt("How fast should it play?"));
parseFloat is necessary to prevent setting the value to zero if the dialogue window is closed without user input.
javascript:document.getElementsByTagName("video")[0].currentTime=parseFloat(prompt("Jump to playback position in seconds:"));
javascript:document.getElementsByTagName("video")[0].currentTime=60*parseFloat(prompt("Jump to playback position in minutes:"));
javascript:document.getElementsByTagName("video")[0].currentTime=document.getElementsByTagName("video")[0].duration/100*parseFloat(prompt("Jump to playback position in percents:"));
Since you cannot have line breaks in bookmarklets you must use a semicolon at the end of each code statement instead.
JavaScript:name=prompt('What is your name?');alert('Hello, '+name);
TheJavaScript protocol can be used in links. This may be considered bad practice, as it prevents access for or confuses users who have disabled JavaScript. SeeBest Practices.
<ahref="#"/w/index.php?title=JavaScript/Bookmarklets&veaction=edit§ion=6" title="Edit section: Examples">edit |edit source]
A large quantity of links may be found onbookmarklets.com, which show a variety of features that can be performed within JavaScript.