在 div 中包含一个网页 [英] Include a webpage inside a div
问题描述
我必须在我网页的 div 中包含一个网页.我想用 DIV
来完成像 iframe
这样的事情.基本上,我将提供一个指向我的 div 的 URL,它必须在其内部打开它...现代 HTML 中有这样的东西吗?我无法使用框架,因为某些浏览器存在框架问题.
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.
推荐答案
不.您不能在另一个 div 元素中嵌入完整的 HTML 文档,因为这是一个块级元素,并且 W3C 已经定义了可以包含在其中的内容.
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:
- 使用 ajax 获取文档(jQuery 摇滚,使用它)
- 提取
元素的内容并将其放入您的
div
元素 - 获取
元素的所有链接和脚本,并将它们附加到现有 pgae 的
元素.
- 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屋!