Home > php教程 > php手册 > 自动设置iframe高度,实现iframe高度自适应

自动设置iframe高度,实现iframe高度自适应

WBOY
Release: 2016-06-07 11:43:08
Original
1505 people have browsed it

自动设置iframe高度,供第三方调用,实现iframe高度自适应;
这个可以解决跨域问题。
iframe 如下<iframe></iframe>iframe 的src地址包含如下代码片段:<iframe></iframe>
 <script><br /> try {<br /> function sethash() {<br /> var hashH = document.documentElement.scrollHeight;<br /> var urlC = "http://domain/setheight.html";<br /> document.getElementById("iframeA").src = urlC + "#" + hashH + "#" + Math.random();<br /> }<br /> } catch (e) { }<br /> </script>
http://domain/setIframeHeight 的代码如下:    /**<br>      *自动设置iframe高度,供第三方调用,实现iframe高度自适应<br>      */<br>     public function setIframeHeight() {<br>         header("Content-type: text/html; charset=utf-8"); <br>         echo '<meta>';<br>         echo '<script><br /> var b_iframe = parent.parent.document.getElementById("showFrame");<br /> //var app_show_left = parent.parent.document.getElementById("aside_left");<br /> var hash_url = window.location.hash;<br /> var hash_width = hash_url.split("#")[1].split("|")[0];<br /> var hash_height = hash_url.split("#")[1].split("|")[1];<br /> if(undefined==hash_height) {<br /> hash_height = hash_width;<br /> hash_width = 0;<br /> }<br /> //b_iframe.style.width = hash_width;<br /> b_iframe.style.height = hash_height+"px";<br /> </script>';<br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template