【发布时间】:2011-04-26 00:14:56
【问题描述】:
有没有办法使用 Javascript(或 Jquery)替换 iframe 的整个内容?
例如,如果我的 iframe 有以下内容...
blah outside of html
<html>
<head>
</head>
<body>
<h1> my title </h1>
</body>
</html>
blah outside of html
..它都可以被你的脚本代替:)
到目前为止我见过的最好的是:
$(youriframe).contents().find('html').html('your content here');
但这仍然不会替换 html 标记之外的内容。我们有一个有趣的场景,我们必须确保所有内容都被替换。
或者创建具有新鲜内容的新 iframe,并简单地替换以前的 iframe。
请不要有关于 src 属性的 cmets。
【问题讨论】:
-
theIframe.parentNode.replaceChild(theIframe, theNewIframe)是一个选项吗? -
为什么更改
src属性不是一个选项?除非我们了解您的要求,否则我们无能为力。 -
哈哈哈我很确定我的要求很明确。无论如何,我们正在发出服务器请求,在服务器上生成一些长时间运行的内容,然后将其返回给客户端。响应数据包括父窗口和 iframe 的内容。
标签: javascript jquery iframe