Displaying static text content with iframe

2019-04-29 19:29发布

I have a svery simple requirement. I have a <div> tag within which I am displaying some text content.

I want to display the same text content in an <iframe>. What I am trying to achieve I have written below. Can anyone please help?

<b>
<div>This is a content which I want to display in iframe</div>
<iframe id="iframe" src=""></iframe></b>

标签: html iframe
2条回答
手持菜刀,她持情操
2楼-- · 2019-04-29 19:46

If it is a static HTML site, create a new page with the content which you want to show and set the src of the <iframe>.

If it is a dynamic page app (server side), create a new page or handler or controller (whatever applies) and set the src of the <iframe>.

These are the best and simplest ways to achieve what you want to accomplish.

查看更多
Juvenile、少年°
3楼-- · 2019-04-29 20:03

Found one more thing which is related to iframe which I think is interesting. You can auto fix the height and width of the iframe according to the content of the window. All you need to do is to include the script written below and just pass the id of the iframe.

<iframe src="" width="100%" id="idIframe" onload="autoResize('idIframe');" ></iframe>     

<script>
function autoResize(id)
{
    var newheight;
    var newwidth;
    if(document.getElementById)
    {
        newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
        newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
    }
    document.getElementById(id).height= (newheight) + "px";
    document.getElementById(id).width= (newwidth) + "px";
} 
</script>
查看更多
登录 后发表回答