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]");
精彩评论