IE 8 iframe border

前端 未结 7 1143
半阙折子戏
半阙折子戏 2020-12-15 15:56

There is a border showing on an iframe and I can\'t get rid of it.

IE 6 and 7 work as intended with a little JavaScript:



        
7条回答
  •  太阳男子
    2020-12-15 16:22

    If you want your code to validate you could do this with javascript. I found the perfect answer when I had this problem a few months ago here

    var iframe = document.createElement("iframe");
     iframe.src = "banner_728x90.gif";
     iframe.width = "728";
     iframe.height = "90";
     iframe.frameBorder = "0";
     iframe.scrolling = "no";
     document.body.appendChild(iframe);
    

    f you want to load another page seamless in the iframe you can do this if you copy and paste this code into the head of your page. I found it on a site with free scripts. The performance is good in most cases

    function getDocHeight(doc) {
        doc = doc || document;
        var body = doc.body, html = doc.documentElement;
        var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
        return height;
    }
    function setIframeHeight(id) {
        var ifrm = document.getElementById(id);
        var doc = ifrm.contentDocument? ifrm.contentDocument: ifrm.contentWindow.document;
        ifrm.style.visibility = 'hidden';
        ifrm.style.height = "10px"; // reset to minimal height in case going from longer to shorter doc
        ifrm.style.height = getDocHeight( doc ) + 10 + "px";
        ifrm.style.visibility = 'visible';
    }
    

    You then give your iframe an id and call the script on load. This is how.

    var iframe = document.createElement("iframe");
     iframe.setAttribute('id', "ifrm1");
     iframe.setAttribute('src', 'http://www.hekcmviw.com/'); // change the URL
     iframe.setAttribute('width', '100%');
     iframe.setAttribute('height', '10');
     iframe.setAttribute('frameBorder', '0');
     iframe.setAttribute('scrolling', 'no');
     iframe.setAttribute('onload' ,"setIframeHeight(this.id)");
     document.body.appendChild(iframe);
    

提交回复
热议问题