[Greasemonkey] Dynamically loading Prototype
Rich Manalang
rich.manalang at gmail.com
Wed Dec 21 10:42:39 EST 2005
Hi all. I've read about the pitfalls with unsafeWindow but I wanted to get
your opinions. I'd like to dynamically create a script reference to the
prototype.js library on a trusted server to make use of the convenience
functions. The questions is... is this kosher... should we distributing
scripts that do this? From what I understand, as long as we avoid passing
GM_* references to unsafeWindow we should be ok, right?
function waitForProto() {
// waits for the prototype lib to load before continuing with the script
if (typeof unsafeWindow.Prototype=='undefined')
window.setTimeout(waitForProto, 1000);
else
alert(unsafeWindow.Prototype.Version);
callMyCode();
}
function loadProto() {
var proto = document.createElement("script");
proto.type = "text/javascript";
proto.src = "http://some.trusted.server/prototype.js";
document.getElementsByTagName("head")[0].appendChild(proto);
waitForProto();
}
window.addEventListener("load", loadProto(), false);
Rich Manalang
http://monkegrease.org
More information about the Greasemonkey
mailing list