Iframe without src but still has content?

前端 未结 7 706
攒了一身酷
攒了一身酷 2020-12-05 06:56

While debugging jquery code on their site ( via chrome developer toolbar)

I noticed that their examples are given under Iframe :

Here - for ex

相关标签:
7条回答
  • 2020-12-05 07:28

    Try it.

    HTML

    <div id="iframecontent" style="display: none;">
        <b>Hello World!</b> <br /> <i>Hello Again !</i>
    </div>
    
    <div style="margin: auto; width: 80%;">
        <iframe height="100" width="100%" src="about:blank" name="myiframe"
         id="myiframeid"> </iframe>
        <br />
        <button id="tryIt" onclick="onTryItClick()">Try It</button>
    </div>
    

    JavaScript:

    <script type="text/javascript">
    function onTryItClick() {
        var content = document.getElementById("iframecontent").innerHTML;
        var iframe = document.getElementById("myiframeid");
    
        var frameDoc = iframe.document;
        if (iframe.contentWindow)
            frameDoc = iframe.contentWindow.document;
    
        frameDoc.open();
        frameDoc.writeln(content);
        frameDoc.close();
    }
    </script>
    

    Reference: http://duleekag.blogspot.com/2014/01/html-iframe-without-src-attribute.html

    0 讨论(0)
提交回复
热议问题