html引用html问题

html-css07

html引用html问题,第1张

通过嵌套iframe 实现引用html页面

<script type="text/javascript">

$(function () {

document.getElementById("ifm").src =""//Url地址

$("#ifm").load(function () {

var h = document.body.clientHeight

var w = document.body.clientWidth

document.getElementById("ifm").height = h + "px"

document.getElementById("ifm").width = w + "px"

})

})

</script>

<body style="overflow-y:hiddenoverflow-x:hidden">

<div id="pageone" style="">

<iframe name="ifm" id="ifm" scrolling="yes" style="background-color: transparent" marginwidth="0" marginheight="0" frameborder="0">

</iframe>

</div>

</body>

将一个html页面中嵌入另一个html页面步骤如下:

1、首先,要嵌入html并不一定要写js代码,如图使用iframe标签,设置其src属性即可。注意其scrolling="auto"以添加滚动条。另外,其width和height要单独设置。

2、其链接到的html页面内容如图所示。给其添加如图meta标签,增加自动刷新功能。

3、在Python编写的httpserver中(Tornado),这两个url的请求都要处理。以本程序为例,用户浏览器载入main以后,main页面中的iframe标签会自动载入todolist。

4、如图是通过浏览器访问main页面,可以看到下面的框框中显示的就是todolist页面的内容。

5、另外,其右侧自带滚动条,而且这个潜入的页面设置了自动刷新,会时刻保持更新。

6、如果关闭了httpserver,会看到如簇所示情况,嵌入的页面刷新失败。但是main页面没有自动刷新,无影响。