简体   繁体   中英

How to you get the contents of an iFrame to insert into a database?

I have created a wysiwyg text editor using an iframe and am trying to save the contents of this.

The HTML for my iframe is:

<iframe name="richTextField" id="wysiwyg" src="page?page_id=3"></iframe>

I am then using a hidden input to submit this to the database:

<input type="hidden" id="text_content" name="text_content" value="">

I am trying to get the contents of this into the value of the input field using JS like this:

$text_content = #wysiwyg.document.getElementsByTagName('body')[0].textContent;
$("#text_content").attr("value", $text_content);

If I set $text_content to just a random string it will work but it won't get the contents of the iframe.

I have tried $("#wysiwyg document body").textContent , #wysiwyg.document.getElementsByTagName('body')[0].textContent and richTextField.document.getElementsByTagName('body')[0].textContent .

richTextField.document.getElementsByTagName('body')[0].textContent is actually what I used in the JS for toggling to the source but it will not work when trying to set it as a variable.

Should I be trying to do something like php serialize() to get this as a variable I can work with? Or are the terms I've tried as my selectors just wrong? Any help with this will be greatly appreciated.

为了将来参考,这是我使用的:

richTextField.document.getElementsByTagName('body')[0].innerHTML;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM