layer 父頁面 調用子頁面方法報錯

1.現象:瀏覽器控制檯報錯
  Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "null" from accessing a cross-origin frame.
2.錯誤原因:不允許跨域(https://blog.csdn.net/u013084331/article/details/51114288)
3.錯誤代碼:
  var body = layer.getChildFrame("body",index);
  var iframeWin = window[layero.find('iframe')[0]['name']];
  iframeWin.子頁面方法();
4.解決方法:
  將html文件發佈到服務器上運行
  報錯的訪問路徑:file:///C:/Users/Desktop/xxx.html
  發佈後的訪問路徑:localhost:8080/xxx/xxx.html
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章