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
 

你可能感兴趣的:(Layer)