file模式访问网页时iframe高度自适应

来源:互联网 发布:java网站访问量统计 编辑:程序博客网 时间:2024/06/06 03:55
最近做到iframe的高度自适应这个问题,网上一搜好多解决方案,而总结起来也就那几种,我逐一尝试这些方案,最后发现在我的项目中都不起作用,后来发现自己做的网页是通过file方式访问的,将网页代码放到apache下通过http协议访问,在iframe加载的时候调用如下js方法:
function SetWinHeight(obj){ var win=obj; if (document.getElementById) {  if (win && !window.opera)  {   if (win.contentDocument && win.contentDocument.body.offsetHeight)    win.height = win.contentDocument.body.offsetHeight;   else if(win.Document && win.Document.body.scrollHeight)    win.height = win.Document.body.scrollHeight;  } }}


果然网页高度能够自适应(对于其他方案应该也有效果,我没有注意去尝试),而通过file方式访问网页同样的的代码log中始终报:Unsafe JavaScript attempt to access frame with URL file:///E:/workspace/html5/exam.html from frame with URL file:///E:/workspace/html5/quiz_preview.html. Domains, protocols and ports must match. 
每种方案都尝试了报的错是这个,只能从这个问题下手解决了,后来发现这种通过file方式跨域访问的方式chrome是默认不允许的,又查如何设置chrome允许跨域访问:最简单的方法在chrome图标右键、属性->目标 在后添加‘ --disable-web-security’
重新启动chrome打开要调的网页,问题果然解决了
原创粉丝点击