steve dp wrote:
Lets say we run: window.alert = function() { };
Is there anyway to 'restore' the original alert() method or is it gone
forever?
No, it hasn't 'gone' anywhere. You've just overridden the reference to it.
I guess a cynic might say that if you remove all references it'll be
swallowed by garbage collection :-) but I doubt that can happen with
in-built host objects.
I know you can do window.alert = Window.prototype.alert, but lets say
you also set Window.prototype.alert = function() { } or lets say we're
in Opera, which doesnt have a Window "class".
Store a reference to it, then restore it when you're finished. Play with this:
<p>Test window.alert</p>
<input type="button" value="test alert"
onclick="alert('hey, it worked');">
<p>Store a reference to window.alert</p>
<input type="button" value="store reference"
onclick="window.keptAlertRef = window.alert;">
<p>Over-ride window.alert</p>
<input type="button" value="over-ride alert"
onclick="window.alert = null;">
<p>Restore window.alert from stored reference</p>
<input type="button" value="restore reference"
onclick="window.alert = window.keptAlertRef;">
--
Rob