What is a Bookmarklet Script?

How do we keep this site running? This post may contain affiliate links — the cost is the same to you, but we get a referral fee. Compensation does not affect rankings. Thanks!

BookmarkA bookmarklet is basically a software application for your browser. But what bookmarklets are most known for is their ability to run a website script from anywhere – in other words, the application is loaded in the browser, and doesn’t have to be called from a particular web page. For example, if you visit our URL shortcut creator, LinkTh.at. You’ll see a bookmarklet which will let you create shortcuts from any webpage, instantly – without having to copy the URL, leave the page, and enter it into the form on LinkTh.at. This creates a huge convenient to clients and proves to be a big time saver. Note: Our URL shortcut service LinkTh.at has been closed due to abuse; we recommend Bit.ly instead. Bit.ly provides a way to save your URL shortcuts, view analytics, and more.

How Do I Create a Bookmarklet?

Developers are often interested in creating bookmarklets for their website applications or forms, as it will allow clients to use their service without having to load their website in a separate window. Common popular services that take advantage of the powers of a bookmarklet include del.icio.us, digg, and other social media networks, as well as various websites running scripts. We’re going to show you the fundamentals to creating your own bookmarklet script.

Bookmarklet Script

With a bookmarklet, all you’re doing is creating a bookmark that runs a script. The difference between the bookmark of a static URL and a bookmarklet, is that with the latter the URL consists of Javscript code, which can execute various functions. Therefore, for most scripts, you simply call the script using javascript:

javascript:

As an example, we call

javascript:alert('Sample alert message');location.href='//www.example.com/new-page/'

The way you actually use this is by creating an anchor (clickable URL) out of the script – so users can right-click your link and create a bookmark out of it. Then, when they load the bookmark, it will load the javascript code and execute your script. Here’s an example: Just an Alert. If you right-click this link and bookmark it, whenever you load up the bookmark you’ll see the alert message.

Advanced: For bookmarklet scripts that only accept POST submissions, you’ll have to create an invisible form and submit it like so:

javascript:myForm=document.createElement("form");
myForm.style.display="none";
myForm.method="post";
myForm.action="http://example.com/";
myInput=document.createElement("input");
myInput.setAttribute("name","description");
myInput.setAttribute("value",document.URL);
myForm.appendChild(myInput);
document.body.appendChild(myForm);
myForm.submit();
document.body.removeChild(myForm);

Have fun!

Alex bring a series of in-depth articles on search marketing and content management systems as well as troubleshooting tips to We Rock Your Web's collection. He is an avid tennis player, nature enthusiast, and hiker, and enjoys spending time with his wife, friends, and dogs, Bella and Lily.

Leave a Reply

1 Comment on "What is a Bookmarklet Script?"

avatar
azwaldo
azwaldo

Was banging my head on how to POST selected text with a bookmarklet, your article provided the solution. Much appreciation, here.

wpDiscuz

Send this to a friend