BlockTarget and more on not opening new windows
One of annoyances of using the web is that many webmasters (or at least their managers) think that forcing a browser to open a new window is a good idea. As I’ve said a number of times, creating a website that automatically opens a new window is almost always a Bad Idea. To eliminate this temptation, I have modified the text editor used on some of my sites so that users cannot create new windows using the HTML target
attribute. This still doesn’t solve the problem of new windows opened using JavaScript, or of new windows being opened by sites I visit. So I decided to look for a solution to automatically remove the target
attribute from links on sites I visit.
Since I use the Safari and Chromium web browsers on OS X, my first impulse was to write a GlimmerBlocker script to remove the target
from links. This would fix the problem on all sites I visit with any browser. I had already written a GlimmerBlocker filter to remove target="_blank"
from some websites, so I just needed modify it into a cleaner general version. Since my brother does much more JavaScript programming than I do, I asked him if he knew a more efficient way to do this. He mentioned one, and also suggested writing a Safari Extension instead of a GlimmerBlocker script.
Before starting a new Extension, I searched for an existing one. It wasn’t on the official Extension list, but someone had already written one:
BlockTarget is an extension for Safari 5. It removes the ‘target’ attribute from links to prevent a new window being opened.
After skimming the source (how open a Safari Extension) for this Extension, I decided to give it a try. I’ve been using BlockTarget for two weeks, and it seems to work well. If you use Safari, this Extension will make the internet a more pleasant place.
BlockTarget is a good solution to part of the problem of new windows, but it can’t fix all instances. It is still possible to open a new window using JavaScript. Developing a universal solution for the alternate methods of opening new windows is a problem for another time. There is also a disturbing trend to generate websites completely through the use of JavaScript. Even if these sites use the target
attribute to open new windows, they do it after BlockTarget has run, so it misses these target
s. I eventually need to find an efficient way to write a script to watch a page and remove all window opening code, but I won’t have time to work on that in the near future. So please, write a clean solution!