在div中包含一个网页 [英] Include a webpage inside a div
问题描述
我必须在我的网页div中包含一个网页。我想要使用 iframe
来处理 DIV
。基本上,我将为我的div提供一个URL,并且必须在其内部打开它...在现代HTML中,我们是否有这样的东西?我不能使用框架,因为一些浏览器对框架有问题。
不。您不能在另一个div元素中嵌入完整的HTML文档,因为这是块级元素,W3C已经定义了可以包含在其中的内容。
但有一个解决方法。请按照以下步骤操作:
- 使用ajax获取文档(使用jQuery文件)
-
< body>
元素的内容并将其放入您的div
元素中 - 获取
< head>
元素的所有链接和脚本,并将它们追加到< head>
元素您现有的pgae。
I have to include a webpage inside my webpage's div. I want somehting like iframe
to be done with DIV
. Basically, I will be providing a URL to my div and it has to open it inside itself... Do we have something like this in modern HTML? I cannot use frames as some browsers have issues with frames.
Nope. You can't embed a complete HTML document inside another div element as this is a block level element and W3C has defined what could be included inside it.
But there is a workaround. Follow these steps:
- Get the document using ajax (jQuery rocks, use that)
- Extract the content of the
<body>
element and put it inside yourdiv
element - Get all links and script of
<head>
element and append them to the<head>
element of your existing pgae.
这篇关于在div中包含一个网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!