How to embed HTML content in a frame in Internet Explorer? Web page that contains frames is shown as a blank page in Internet Explorer.
I have checked FRAMESET, FRAME, embed, and object tags. All these have 'src' attribute to specify the address of the document to embed. But I want to embed HTML content into the frame.
The have the attribute 'srcdoc' to specify the HTML content of the page to show in the frame. But Internet Explorer doesn't support .
Can you suggest a solution for this?
You can use iframe.contentWindow.document.write()
to embed HTML in iframe. The sample code is like below:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<iframe id="iframe1">
</iframe>
<script>
var iframe = document.getElementById('iframe1');
iframe.contentWindow.document.write("<html><body>Hello world</body></html>");
iframe.contentWindow.document.close();
</script>
</body>
</html>