一、Iframe 的自适应方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <iframe name="mainFrame" id="mainBodyFrame" src="/main" frameborder="0" scrolling="no" width="100%" height="900px" onload="setIframeHeight(this)"></iframe> <script type="text/javascript">
function setIframeHeight(iframe) { if (iframe) { var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow; if (iframeWin.document.body) { iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight; } } };
window.onload = function() { setIframeHeight(document.getElementById('mainBodyFrame')); }; </script>
|
二、刷新页面
1 2 3 4 5 6 7 8
| //刷新本页: <script language=javascript>window.location.href=window.location.href;</script> //刷新父页: <script language=javascript>opener.location.href=opener.location.href;</script> //转到指定页: <script language=javascript>window.location.href='yourpage.aspx';</script>
|
三、top.location.href和localtion.href有什么不同
1 2 3 4 5 6 7 8 9 10 11
| //在顶层页面打开url(跳出框架) top.location.href=”url” // 仅在本页面打开url地址 self.location.href=”url” //在父窗口打开Url地址 parent.location.href=”url” //用法和self的用法一致 this.location.href=”url”
|
top.location.href 可以用在当后台使用iframe 框架作为主体显示部分时,当用户身份过期,需要登陆,登录页面会在iframe显示,而登录成功后还是在ifrmae 中显示,如下图:


解决方法:
1 2 3 4 5 6
| <script type="text/javascript"> if (window != top) { top.location.href = location.href; } </script>
|
四、jquery动态加载html页面
1 2 3 4 5 6 7 8 9 10 11
| <script type="text/javascript"> $(function() { $.get("/include/left.html", function(data) { $("#admin-left").html(data); }); }) </script>
|
您的打赏,是我创作的动力!不给钱?那我只能靠想象力充饥了。
微信支付
支付宝