Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to get entire contents of frame

Tags:

javascript

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.

like image 485
thf Avatar asked Oct 19 '25 02:10

thf


1 Answers

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]");
like image 142
Mrchief Avatar answered Oct 22 '25 05:10

Mrchief



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!