views:

371

answers:

1

In Firefox it's possible using the following...

HTMLDocument.prototype.__defineGetter__("cookie",function (){return "foo=bar";});
HTMLDocument.prototype.__defineSetter__("cookie",function (){});

This doesn't cause any errors in WebKit, and WebKit definitely supports __defineGetter__ and __defineSetter__, but it doesn't work. Guessing WebKit is protecting that property somehow.

So, any ideas of how to achieve the same effect in WebKit?

+1  A: 

Have you tried do define the getter/setter pair on the document object itself, instead on the prototype?

document.__defineGetter__("cookie", function() {} );
document.__defineSetter__("cookie", function() {} );

I know it shouldn't matter, but I don't underestimate browser quirks. Even with WebKit.

Update

I've done some tests in Chrome 2 and it appears that it only allows defining a setter. Anyway, I'm not sure how valid this observation is to WebKit, as Google Chrome uses a different JavaScript interpreter than WebKit.

Ionuț G. Stan
Nice idea, but unfortunately that also doesn't work in Safari (neither getter or setter).
netnichols