Javascript Bookmarklet Create Javascript Bookmarklet in Google Chrome
You might have seen some of the popular sites providing you an option of bookmarklet its basically a Javascript Bookmarklet, which you can drag to your favorites bar and after clicking on that it will perform some operation like opening a new window with pre populated information or performing something on current screen.
It is easy to create javascript bookmarklets, in which you can write your custom javascript code to perform some functions.
I will show you how to create simple bookmarklet in different browsers.
So on clicking of this bookmarklet, we will just display some information in alert. This is just a kind of “Hello World” bookmarklet for those who don’t have idea about it. Same can be extended to implement more complex operations.
We will use following javascript code for this.
alert(“Hi, How are you ?”);
Let’s start!
How to Create Javascript Bookmarklet in Google Chrome ?
- To create a bookmarklet in google chrome, make sure your favorites bar is visible on screen.
- Right click on favorites bar and click on “Add Page…” option.
- It will show following screen
- In the Name tab, enter the name of your bookmark.
- Now in URL part, we will put our JavaScript code prepended by “javascript” and we will create a simple function which we will call.
- So now our final URL will be javascript:function test() {alert(‘Hi, How are you ?’);} test();
- Click Save and we are done.
We have just created our first javascript bookmarklet in javascript.
Whats the real use case ?
Same method can be used to do some complex processing like creating forms for submission of information for a website, do some analysis on webpage like finding email addresses from webpage, finding urls from webpage with this simple JavaScript code.
Have a quick look at the video to know about – how to create bookmarklets in Google Chrome browser easily and extract contents from websites using JavaScript.
Tell me if you can use it to create some kind of useful stuff for your use and do share it with everyone.
Just checkout my another Javascript related blog post Javascript Function to Replace All Occurances of String
Leave a Reply