Is It Possible to Add JavaScript Code to a Widget?

Specifically, I'm looking at TwitThis

http://twitthis.com/

to add as a widget I can then add to the Main Sidebar widget set.

Brad Kozlek's picture

There should be no problem

There should be no problem adding javascript to a widget.

Tried it - It Doesn't Work

Nothing shows when published.

Brad Kozlek's picture

Widget code is there

The widget code is there (view the source of the blog page). I think there are extra line breaks in the javascript from when you copied and pasted the code. Javascript tends to not like that.

The document.write() method should all be on one line. In other words, everything below should all be on one line, with no breaks:

document.write('<a href="javascript:;" onclick="TwitThis.pop();"><img src="http://s3.chuug.com/chuug.twitthis.resources/twitthis_grey_72x22.gif" alt="TwitThis" style="border:none;" /></a>');

It Worked!

That was the problem. Added a center tag and a break for some white space beneath the image. However, I'm now seeing some blog post text at the top of a the screen on certain posts. For example, see

http://www.personal.psu.edu/bxb11/blogs/brett_bixler_e-portfolio/2008/12...

Is this an artifact of the widget?

Syndicate content