HTML <frame> SRC-attribute - use html-code instead of URL

前端 未结 4 886
Happy的楠姐
Happy的楠姐 2021-02-05 16:32

Is there a way to use pure html-code to display inside a frame instead of having to link to a specific URL/file?

For example:

NOT like this

4条回答
  •  隐瞒了意图╮
    2021-02-05 17:07

    maybe you could inject HTML into the iFrame/Frame like described in this article:Injecting HTML into an IFrame by Michael Mahemoff.

    Something like this:

    var content = "Hello World!";
    
    var iframe = document.createElement("iframe");
        document.body.appendChild(iframe);
    
    var frameDoc = iframe.document;
        if(iframe.contentWindow)
            frameDoc = iframe.contentWindow.document; // IE
        // Write into iframe
        frameDoc.open();
        frameDoc.writeln(content);
        frameDoc.close();
    

    HTH,

    --hennson

提交回复
热议问题