Edit for iframe contents

女生的网名这么多〃 提交于 2020-01-24 12:05:30

问题


Is there anyway I can edit the html content of an iframe inside a webpage?

I have the following code:

<iframe src="sample.html"></iframe>

I want to edit the contents of sample.html without literally touching the html code. And I want this editor to be embedded on the website. Thank you so much!


回答1:


You can access the document of the <iframe> like so:

iframedoc = document.getElementById("my_iframe").contentDocument;
iframedoc.getElementById("element_in_iframe").do_something();

Note that this only works if the iframe is on the same domain as your parent page.




回答2:


iframedoc = document.getElementById("my_iframe").contentDocument;
iframedoc.getElementById("element_in_iframe").do_something();

If the iframe content is from another website you can use httrack to download the website and host it on your local server to use the above code.

Yours truly

CEE Creative web designer



来源:https://stackoverflow.com/questions/6834014/edit-for-iframe-contents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!