jquery - iframe access denied in IE on some pages

前端 未结 5 1445
深忆病人
深忆病人 2020-12-05 15:36

I\'m the author of printThis, a jquery plugin for printing.

https://github.com/jasonday/printThis

I have a user that has brought up an issue, that I have bee

5条回答
  •  自闭症患者
    2020-12-05 16:11

    In your code, you are using setTimeout to execute your function after the iframe has loaded.

    // allow iframe to fully render before action
    setTimeout ( function () {
    ...
    }, 333 );  //333ms
    

    but this is a mistake as you don't know if the time given is enough to load the iframe or not. Javascript execution is asynchronous so, there is no guarantee that setTimeout will offset the execution of the function until iframe loads. Since load time is different for different pages. Some cannot execute the code properly, pointing to the line which you find to be causing errors.

    var $doc = $("#" + strFrameName).contents();  //only after loading
    

    The correct way is to use event load or onload to get to know if the DOM object has loaded properly or not.

    
    //or
    
    

提交回复
热议问题