开发者

Change Iframe Content from Cached HTML?

开发者 https://www.devze.com 2022-12-24 05:40 出处:网络
Is there any way that I can change the content of iframe from a cached html string? I am not talking about iframe.Attrib开发者_如何学Pythonute[\"src\"] = \"url\", but rather given a string of html and

Is there any way that I can change the content of iframe from a cached html string? I am not talking about iframe.Attrib开发者_如何学Pythonute["src"] = "url", but rather given a string of html and change the content.

An ugly workaround might be saving the html into a file and change iframe src to it. Any other ways? Maybe javascript can help?


If you can control the contents of the iframe html, you could do something like this:

Expose a method as such:

<script type = "text/javascript">
function setData(str)
{
$('html').html(str);
}
</script>

and call it like

document.iFrameName.setData(myHtmlStr);

from the parent frame.


Stefan Kendall's solution is a good one. As a fallback, if you can't or don't want to use jQuery, you can also document.write into the iframe. Here's an example which I believe will eliminate all the cross-browser quirks.


Bearing in mind this must be on the same domain, otherwise you're into rpc territory...

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号