DEV Community


A simple bookmarklet to tweet the current page

codepo8 profile image Christian Heilmann Updated on ・2 min read

I like tweeting about pages I read in the following format:


Most "share this" buttons add a lot of cruft and if there is none, it is annoying having to copy the text first and then the URL into Twitter.

With this bookmarklet, you can highlight some text, click the bookmarklet and get a tweet window in a new tab:

Enter fullscreen mode Exit fullscreen mode


  • We wrap the whole thing in an IIFE to avoid the browser redirecting to "javascript://"
  • We get the anchorNode of the current Selection object
  • We check the type. If it's a text node, we read the data, if it is HTML, we get the innerText
  • We open a window (which these days results in a new tab) and call the Twitter intend with the text followed by two linebreaks and the URL of the document.

That's it.

Here's the minified version to add to your bookmarks:

Enter fullscreen mode Exit fullscreen mode

Copy this, go to your bookmarks toolbar (change in view if it isn't visible), and set the location as the code above:

Bookmark settings

Alternatively, go to the post on my blog (as disallows javascript: links) and drag the "tweet this" link to your toolbar.

Voilà, happy tweeting.

Discussion (6)

dazzknowles profile image
Dazz Knowles

Anyone got this working on Chrome (76.0.3809.100, Windows)? It does nothing when I then click on the bookmark.

codepo8 profile image
Christian Heilmann Author

Oops, there was a bug, I am editing this now. You can also drag the bookmarklet link on my blog into the chrome bar:

dazzknowles profile image
Dazz Knowles

All working now, thanks and good work :)

cescquintero profile image
Francisco Quintero 🇨🇴

I suffer the want thing when I want to share stuff.

Giving this a shot

jankoweb profile image

Text is not inserted in Chrome. I think that the url changed to .

jankoweb profile image

this work for me:


Forem Open with the Forem app