How to catch JavaScript errors in all Iframes (with window.error)?

前端 未结 2 1930
面向向阳花
面向向阳花 2020-12-06 03:39

I know one can add event listener for window.error.

However when working with Iframes, each iframe has its own window element, and window.error

2条回答
  •  鱼传尺愫
    2020-12-06 03:57

    This might work.

    function myHandler(msg, url, line){
      //do stuff here...
    }
    
    //hook in all frames...
    function addErrorHandler(win, handler){
      win.onerror = handler;
      for(var i=0;i

提交回复
热议问题