arrow-left arrow-right brightness-2 chevron-left chevron-right facebook-box facebook loader magnify menu-down rss-box star twitter-box twitter white-balance-sunny window-close
Instapaper bookmarklet, updated to close the tab every time
1 min read

Instapaper bookmarklet, updated to close the tab every time

A few months ago I modified the bookmarklet provided by Instapaper so that it would automatically close the tab I was instapapering, thereby obviating an extra step that I otherwise would have to take 100% of the time.

While I didn’t mention it in the earlier post, I knew that some sites would just ignore the window.close() method. I’m aware that some browsers generally won’t allow JavaScript to close a tab/window if that tab/window wasn’t itself opened via JavaScript, but that didn’t seem to explain why some sites — whose URIs were typed in manually — would let me close them with JavaScript and others wouldn’t.

After tiring of trying to determine why this was the case, I decided to route around the issue entirely by re-opening the to-be-instapapered site via JavaScript, and then calling the window.close() method. With that order of events, the tab gets closed every time, and to the user the re-load is completely transparent: click the bookmarklet and the tab closes immediately, followed by the closing of the status pop-up.

The same caveats remain for this version of the bookmarklet as for the last: 1) I’ve tested it only with Safari 4/Mac and 2) you still will need to modify it to add your unique user key (as explained in the previous post).

To get/use the bookmarklet, drag [this link](javascript:var%20d=document,w=window,e=w.getSelection,k=d.getSelection,x=d.selection,s=(e?e():(k)?k():(x?x.createRange().text:0)),f='https://www.instapaper.com/b',l=d.location,e=encodeURIComponent,p='?v=4&k=USER_KEY&u='+e(l.href) +'&t='+e(d.title) +'&s='+e(s),u=f+p;var xwin = w.open(location.href, "_self");xwin.close();try{if(!/^(..)?instapaper([^.])?$/.test(l.host))throw(0);iptstbt();}catch(z){a%20=function(){if(!w.open(u,'t','toolbar=0,resizable=0,status=1,width=250,height=150'))l.href=u;};if(/Firefox/.test(navigator.userAgent))setTimeout(a,0);else%20a();}void(0)) to your bookmarks bar.

You've successfully subscribed to P O L Y M A T H.
Success! Your account is fully activated, you now have access to all content.