Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call native javascript function that has been "erased" by the web page

Tags:

javascript

Let's say a web page did this:

window.alert = console.info;

How can I, through browser console, recover the original alert method to get the modal back?

I tried accessing the window.prototype but it does not exist. I would also like to know if such process exist in general (like, if String.* was erased/redefined by a website or if website made a console.log = window.alert).

like image 821
Xenos Avatar asked Jul 26 '18 09:07

Xenos


People also ask

Why is Document write () not recommended anymore?

Another reason not to use document. write() is it doesn't support XHTML, but its not an issue since most web development uses HTML. Since document. write() fires after a page has finish loading, it causes performance issues and sometimes, may not even fire at all.

Does document write overwrite?

write after the document has loaded, it overwrites the entire document. If it is run before that, it does not overwrite it.


1 Answers

What you can do, is create an iframe attach it to page and then copy alert method from that iframe

//someone did this
window.alert = null;

//you are doing this
var frame = document.createElement('iframe');
document.body.appendChild(frame);
window.alert = frame.contentWindow.alert.bind(window);
document.body.removeChild(frame);
like image 148
ned Avatar answered Sep 17 '22 18:09

ned