[Greasemonkey] Adding methods/properies to document object with GM

Blake West blakewest at gmail.com
Wed Jul 20 11:31:18 EDT 2005


There has been some discussion about global objects in some of the
other threads that I didn't really understand. But now I wonder if I
am violating a best practice in a script I've written.

My script adds a couple methods and properties to the document object
when it's initialized and also adds a link on the page to activate one
of the methods. Like this:

****************

document.foo = 'bar';

document.func = function(){
    window.alert(document.foo);
}

function initScript(){
		var div = document.createElement('div');
		div.innerHTML = '<a onclick="document.func()">click me</a>';
		var content = document.getElementById('content');
		content.parentNode.insertBefore(div,content.nextSibling);
}

window.addEventListener("load",initScript(),false);

****************

Is it okay for me to be adding properties and methods to document? 
Am I causing a security problem by adding methods to the content global object?

Thanks,
Blake


More information about the Greasemonkey mailing list