Another way to block the Digg Bar

A lot of developers don’t like having their sites loaded into a frame with Digg’s new DiggBar, inspiring several scripts to get rid of the bar. John Gruber came up with a short PHP script that prevents the page from loading with a nasty message if it detects that it’s being loaded in DiggBar’s frame. Gruber’s script inspired Phil Nelson’s WordPress plugin, which adds that script to any WordPress site.

I decided on a different route, using JavaScript instead of PHP and reloading the page outside the frame instead of displaying a message. The result is my Undigg WordPress plugin, which you can download here.

My plugin simply adds the following bit of JavaScript code to the page:

<script type="text/javascript">if ((top !== self) && ((document.referrer+"").substring(7,11) == "digg")) top.location.href = self.location.href;</script>

This is very similar to a standard frame killer, except it only affects the Digg bar while letting other frames load your page.

To install it, unzip the archive, drop ‘undigg.php’ in /wp-content/plugins, and enable it in the plugins screen.

Leave a Reply