iframe使用方法

实现iframe高宽度自适应、无滚动条、无边框

父页html代码:

<iframe id="iframe_A" src="Market-P2.html"  style="z-index: 1; visibility: inherit; 100%;border: none; "></iframe>

子页js代码:

//调整父级窗口iframe高度
   objParent.setParentIframeHeight('iframe_A');



//父页面辅助对象
var objParent = {
    //设置框架高度
    //iframe 对象
    setIframeHeight: function(iframe) {
        if (iframe) {
            var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
            if (iframeWin.document.body) {
                var _height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
                console.log(_height);
                iframe.height = _height;
            }
        }
    },

    //子页面设置父页面框架高度
    //iframe:框架id
    setParentIframeHeight: function(frameID) {

        objParent.setIframeHeight(parent.document.getElementById(frameID));

    }


};
原文地址:https://www.cnblogs.com/zyx321/p/13402193.html