开发者

Javascript to get entire contents of frame

开发者 https://www.devze.com 2023-03-22 07:33 出处:网络
I want to have a script rewrite a simple text-file opened up as the source of a frame 开发者_如何学运维-- one that lacks any html.I tried frames[1].document.innerHTML but without success.I even tried

I want to have a script rewrite a simple text-file opened up as the source of a frame 开发者_如何学运维-- one that lacks any html. I tried frames[1].document.innerHTML but without success. I even tried .outerHTML and got nothing. Can I either (a) get from the frame the entire contents of the frame to manipulate using the script and then .write() back the result to the frame? Or (b) add <html> and <div> tags, wrapping the document so I can get the inner html and then manipulate that? Any help appreciated.


As long as your main page and iFrame page follow Same Origin policy, you can access frame's html like this:

window.frames['iframe01'].document.body.innerHTML

or

window.frames['iframe01'].contentDocument.documentElement.innerHTML

To write:

window.frames['iframe01'].contentDocument.write("[content here]");
0

精彩评论

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