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>
    
  • 相关阅读:
    【UNR#3】白鸽
    【POI2011】Garbage
    【NOI2010】海拔
    【HNOI2012】矿场搭建
    【UOJ#177】欧拉回路
    【BZOJ4500】矩阵
    【CF429E】Points and Segments
    【agc001F】Wide Swap
    【BZOJ2138】stone
    【JSOI2009】游戏
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/13081254.html
Copyright © 2011-2022 走看看