views:

140

answers:

2

I want to add the Digg button on my webpage but don't want to add the script tag directly on the page.

<div class="digg">
<script type="text/javascript">
    digg_url = '';
    digg_bgcolor = '#99ccff';
    digg_skin = 'compact';
    digg_window = 'new';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div>

What are the some of the unobstrusive ways of adding the JavaScript for the Digg button?

A: 

Other than setting those "digg_" variables in a separate file, there's not much you can do.

Including an external Javascript from digg.com isn't really "intrusive" anyway.

Triptych
+1  A: 

The diggthis.js script either places the button where the script tag lies or looks for an anchor tag with a class name of "DiggThisButton". However, it tries to run before all the DOM elements are created. So, instead of having script included in the head of the HTML document, you need to place it at the bottom of the page.

Here's another way of doing this ( the .... represents any additional content):

<html>
<head>
<script type="text/javascript">
    digg_url = '';
    digg_bgcolor = '#99ccff';
    digg_skin = 'compact';
    digg_window = 'new';
</script>
.....
<body>
....
<div class="digg">
 <a class="DiggThisButton"></a>
</div>
....
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</html>
Jose Basilio
The default implementation of Digg adds the Digg count etc in an iframe. Is it possible alter that behaviour ? I only need to display the digg counter. Thanks.
Iris
This cannot be done using the diggthis.js script, you may have to read through the Digg API documentation for alternative ways.
Jose Basilio
Iris