Dynamically loading Javascript files

The little snippet below lets you load JS files dynamically, making it easier to load jQuery or mootools for scripts like GreaseMonkey or within Firebug.

var jsfile = document.createElement("script");
jsfile.setAttribute("type", "text/javascript");
jsfile.setAttribute("src", "
http://ajax.googleapis.com/ajax/libs/mootools/1.2.2/mootools.js");
document.getElementsByTagName("head")[0].appendChild(jsfile);

Using Firebug, I used the following mootools code to hide some elements as a test to see if the script actually loaded.

$each($$('.saveType, .perType'), function(item) {
  item.setStyle('display', 'none');
});

"Why would you do such a thing?"

Someone was hosting photos that he took himself and decided to take them down one day.

Strangely enough, he got an email from a "businessman" who was threatening legal action if he didn't put those images back because they affected his advertising.

Full story here.

If you're having trouble reading the images from the story, the direct links are easier to read.

  1. I'm gonna get sued 1.gif
  2. I'm gonna get sued 2.gif
  3. I'm gonna get sued 3.gif

LOL stupid people... just hope you don't have to deal with them.

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog