zoukankan      html  css  js  c++  java
  • 【iframe__窗口】iframe大小随浏览器窗口大小而改变

    iframe大小随浏览器窗口大小而改变

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>iframe</title>
    </head>
    <body>
        <iframe id="mainiframe" style="background-color:red"></iframe>
        <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
        <script type="text/javascript">
            window.onresize = function () { changeFrameHeight(); }
    
            $(function () {
                changeFrameHeight();
            });
    
            $(document).ready(function () {
                //var url = getCookie('pre_url');
                //if (url) {
                //    $("#mainiframe").attr('src', url);
                //} else {
                //    $("#mainiframe").attr('src', '');
                //}
            });
    
            function changeFrameHeight() {
                var ifm = document.getElementById("mainiframe");
                ifm.height = document.documentElement.clientHeight - 100;
                ifm.width = document.documentElement.clientWidth - 100;
                console.log("document.documentElement.clientWidth", document.documentElement.clientWidth);
                console.log("document.documentElement.clientHeight", document.documentElement.clientHeight);
            }
    
            function check() {
                pre_url = window.frames['mainiframe'].document.location.pathname;
                if (pre_url.indexOf("blank") == -1) {
                    setCookie('pre_url', pre_url, 10);
                }
            }
    
            function getCookie(c_name) {
                if (document.cookie.length > 0) {
                    c_start = document.cookie.indexOf(c_name + "=")
                    if (c_start != -1) {
                        c_start = c_start + c_name.length + 1
                        c_end = document.cookie.indexOf(";", c_start)
                        if (c_end == -1) c_end = document.cookie.length
                        return unescape(document.cookie.substring(c_start, c_end))
                    }
                }
                return ""
            }
    
            function setCookie(c_name, value, expiredays) {
                var exdate = new Date()
                exdate.setDate(exdate.getDate() + expiredays)
                document.cookie = c_name + "=" + escape(value) +
                    ((expiredays == null) ? "" : ";path=/;expires=" + exdate.toGMTString())
            }
        </script>
    </body>
    </html>
    
  • 相关阅读:
    .net Core
    4.1 愚人节
    迷茫了....
    关于Plupload结合上传插件jquery.plupload.queue的使用
    兼容浏览器 回车键 keydown事件
    JS判断是否是IE浏览器的几种方式
    IE IE8 iframe的onload方法分析 IE浏览器onload事件失效
    java 获取请求的完整url地址
    SQLSERVER 数据库基础操作
    java 四舍五入 保留两位小数
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/13081254.html
Copyright © 2011-2022 走看看