Here’s the problem, a web site allows you to use html but filters script blocks. You really want to use some cool javascript though.
How to you do it?
Use an anonymous javascript function on the onload event of an image. If you read my article about WEDJE and/or Mike Davidsons’ article about the same you’ll see the basic format for setting up script for slow loading servers without stopping a page load. Based upon that knowledge I decided to take it a step forward. As I normally do.
Testing in all browsers show that they support the onload event for and image tag. What this means is if the image was successfully loaded then the onload event is triggered. So we’ll use that to call an image off our server but for everyones sake I’ll replace the onload with onclick for demo purposes.
<div id=”needed_script_container”></div>
<img src=”http://www.techraving.com/images/ror.gif” border=”0″ onclick=”" />
Having that basic setup let’s add the base javascript to call our external javascript file using the anonymous function to create a script element dynamically.
<div id=”needed_script_container”></div>
<img src=”http://www.techraving.com/images/ror.gif” border=”0″ onclick=”(function() { s=document.createElement(’script’); s.type=’text/javascript’; s.src=’http://www.techraving.com/javascript/anon.js’; setTimeout(’document.getElementById(\’needed_script_container\’).appendChild(s)’, 1); })()” />
The reason the div is needed is to attach the new script element. The setTimeout is to delay the attachment of the element just a little to make sure the page has successfully loaded it. For slower sites the timeout can be increased.
Now with that code placed in a webpage and clicking the graphic the onclick event is triggered and activates the inner javascript. Dynamically creating the seed script block with the div means that further javascript functions can now be used.
Using the above code click the image below to see it in operation:

The called javascript file merely includes: alert(”This page location: ” + window.location.pathname + “. I am glad to meet you!”);
So far I’ve found no real reason to use this, yet! But hey now we know right!