我是否可以在网页中编辑 iframe 的 html 内容?
我有以下代码:
<iframe src="sample.html"></iframe>
我想编辑 sample.html 的内容,但不直接接触 html 代码。我希望将此编辑器嵌入到网站中。非常感谢!
最佳答案
您可以访问 <iframe>
的文档像这样:
iframedoc = document.getElementById("my_iframe").contentDocument;
iframedoc.getElementById("element_in_iframe").do_something();
请注意,这仅适用于 iframe 与您的父页面位于同一域中的情况。
关于javascript - 编辑 iframe 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6834014/