[FE] 被動檢測 iframe 加載 src 成功失敗的一種思路和方式 (Vue)


 

思路:設置定時器一個,n 秒后設置 404 或其它,此時給 iframe 的 onload 事件設置回調函數,加載完成則取消定時器。

 

示例:

data () {
  return {
    handler: null
  }
}

created () {
    this.handler = setTimeout(() => {
      const iframe = document.querySelector('#iframe_id')
      iframe.src = './404'
    }, 3000)
}

mounted () {
    const self = this
    const iframe = document.querySelector('#iframe_id')

    iframe.onload = function () {
      self.iframeCompleteLoad = true

      clearTimeout(self.handler)
    }
}

 

Link:https://www.cnblogs.com/farwish/p/14407369.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM