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

后端 未结 1 1652
梦如初夏
梦如初夏 2021-01-18 20:50

Let\'s say a web page did this:

window.alert = console.info;

How can I, through browser console, recover the original alert method

相关标签:
1条回答
  • 2021-01-18 21:20

    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);
    
    0 讨论(0)
提交回复
热议问题