Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

iframe

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

<iframe src="left.html" name="left"></iframe>

but like this

<iframe src="here goes the html code" name="thank you SO"></iframe>
like image 890
user966041 Avatar asked Mar 21 '12 12:03

user966041


People also ask

Can I put HTML in an iframe?

The <iframe> creates an inline frame, which embeds an independent HTML document into the current document.

How can I change src attribute in iframe?

To change the iframe src attribute, we will be using a select drop down menu, and a button element to activate the function that will change the src attribute.

What is iframe src in HTML?

The HTML <iframe> src attribute is used to specify the URL of the document that are embedded to the <iframe> element. Syntax: <iframe src="URL"> Attribute Values: It contains single value URL which specifies the URL of the document that is embedded to the iframe.


1 Answers

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 = "<html><body><b>Hello World!</b></body></html>";

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

like image 94
hennson Avatar answered Oct 14 '22 06:10

hennson