Generated social media links I'm still fairly new with JavaScript, and wrote something to generate some social media links on my page.  The idea was to have that script grab the necessary URL info and feed it to the social media APIs.

&lt;script type="text/javascript"&gt;

    // print links
    titleElement = urlencode(document.title);
    linkElement = urlencode(location.href);

    document.write ("&lt;a href='http://facebook.com/sharer.php?u=" + linkElement + "&amp;t=" + titleElement + "' target='_blank'&gt;&lt;img src='socialMedia/social_facebook.png' border='0' class='png tip' title='Facebook :: Post on your wall!' alt='Facebook' /&gt;&lt;/a&gt;");

    document.write ("&lt;a href='http://stumbleupon.com/submit?url=" + location.href + "&amp;title=" + titleElement + "' target='_blank'&gt;&lt;img src='socialMedia/social_stumbleupon.png' border='0' class='png tip' title='Stumbleupon :: Share this page!' alt='Stumbleupon' /&gt;&lt;/a&gt;");

    document.write ("&lt;a href='http://twitter.com/?status=" + titleElement + "%20-%20" + linkElement + "' target='_blank'&gt;&lt;img src='socialMedia/social_twitter.png' border='0' class='png tip' title='Twitter :: Tweet this page!' alt='Twitter' /&gt;&lt;/a&gt;");

    document.write ("&lt;a href='http://digg.com/submit?phase=2&amp;url=" + linkElement + "' target='_blank'&gt;&lt;img src='socialMedia/social_digg.png' border='0' class='png tip' title='Digg :: Digg this page!' alt='Digg' /&gt;&lt;/a&gt;");

    document.write ("&lt;a href='http://del.icio.us/post?url=" + linkElement + "&amp;title=" + titleElement + "' target='_blank'&gt;&lt;img src='socialMedia/social_delicious.png' border='0' class='png tip' title='Del.icio.us :: Bookmark this page!' alt='Del.icio.us' /&gt;&lt;/a&gt;");

&lt;/script&gt;
Use the var keyword to declare titleElement and linkElement in this scope, otherwise they will always be global variables and you'll have no choice about it.

Using var will still put them in the global scope until you wrap this logic in a closure:

(function() {
    // var titleLink...
})();


You should still take the advice of @NebulaFox - don't use document.write.