简体   繁体   中英

Can I re-enable Window.alert after override?

If I have a page overriding window.alert box:

Window.alert = function() {}

can I re-enable the alert box if I have access to the Javascript?

I guess I would save the original alert function off somewhere else and then reassign it back to it.

 var originalAlert = window.alert; window.alert = function(stuff) { console.log('alert invoked'); } alert(); // displays a message in the console var newWindow = window.open(); window.alert = newWindow.alert; newWindow.close(); alert(); // alerts a message 

I don't know that I would open a new window just to get the alert function, but that function is native code, so once it's been closed over, you can't get it back without some crazy hack like this. At least not that I'm aware of.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM