When using Kindeditor, I want to use Ajax to transfer values, but the method of encapsulating it through the editor does not work. The reason is that the editor is placed in another jsp page and loaded through an iframe. At the same time, this iframe display="none" must be triggered by an event.
Since the original method doesn't work, I have to get it through jQuery. The first thing I thought of was to read the content in the content "textarea", that is: $("#editor").html(), but it cannot be obtained in this way. So I wanted to get it by getting the content in the iframe, but I couldn't get it. Finally, I found the final result through firefox's debug view:
As can be seen from the picture above, to get For the content "The weather is very good today", we only need to get the content in the specified body.
Processing process: First get the outermost iframe, get the sub-element iframe inside through the iframe, and then get the body inside after entering the first layer. As follows:
Where contents(): Find all child nodes (including text nodes) inside the matching element. If the element is an iframe, find the document content.
The following provide several methods to obtain the content of elements in iframe:
Get the content of the textarea element in the iframe