剪贴板实现跨域iframe高度自适应 @ 阅微堂
剪贴板实现跨域iframe高度自适应
zhiqiang10月 9, 2006 IT技术
这两天玩xiaonei用到的一个技术,虽说是跨域iframe,但要求对外部网页和内部网页都有编辑权限,所以只能用在一些特殊场合。
如果是域内的iframe,高度自适应非常简单,给iframe加入onload属性即可:
marginheight=1 width='100%' scrolling='no' border='0'
frameborder='0'
onLoad='this.height=iframeUpload.document.body.scrollHeight'
target='_blank' style="font-size: 9pt">
这样的方法,baidu一下有很多,一些复杂的方式考虑了浏览器差异等,某些情况下更有效更稳定。不过为安全因素,所有游览器都禁止了不同顶级域名的iframe与其父窗口之间的通信,上面的方法也全失效了。
在http://www.ikown.com/html/show-id-106.html提到另一种实现的技巧,不过需要完全征用用户的剪贴板,后来在code的提示下,可以在基本不影响用户剪贴板使用的情况下,做同样的事情。完整代码如下:
src="http://othersite/a.html" width="100%"
height="700px" frameborder="0" onload="function
resetIframeHeight(){setTimeout(resetIframeHeight,1000);var
str=window.clipboardData.getData('text'); var
obj=document.getElementById('cwin'); if(str.match(/^frameHeight=
\d+x/)){ obj.style.height=parseInt(str.match(/\d+/))
+'px';window.clipboardData.setData('text',str.replace(/
^frameHeight=\d+x/, "));}}setTimeout(resetIframeHeight,1000);">
下面是http://othersite/a.html的代码
i love it.
Acronis Cyber Protect/Backup Remote Code Execution
-
The Acronis Cyber Protect appliance, in its default configuration, allows
the anonymous registration of new protect/backup agents on new endpoints.
This AP...
1 年前
没有评论:
发表评论