Un modo c'è, ma se lo vedi rabbrividisci:
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>New Document</title>
<style type="text/css">
* {
behavior: url(HTMLElement.htc);
}
</style>
<script type="text/javascript">
if (window.ActiveXObject) var HTMLElement = new Function();
HTMLElement.prototype.test = 'its work';
</script>
</head>
<body>
<div onclick="alert(this.test)">text</div>
</body>
</html>
codice:
<PUBLIC:ATTACH event="onpropertychnage"/>
<script type="text/javascript">
var HtmlElement = new HTMLElement();
for (var i in HtmlElement)
{
this[i] = HtmlElement[i];
}
</script>
In passato ho avuto lo stesso problema, ma poi ho scelto di seguire una strada completamente diversa ( sia per problemi di intrusività, sia perchè mai e poi mai mi abbasserei a un tal punto da usare un file .htc ):
codice:
function GET(el) {
return !!el
? new GET.klass(el.constructor == String
? document.getElementById(el)
: el
)
: null;
}
GET.klass = function(el) {
this.el = el;
}
GET.klass.prototype = {
'test': function() {
alert(this.el);
}
}
//Esempio
GET("unDiv").test();