When using Kindeditor, you want to use Ajax to pass values, but the method encapsulated by editor does not work because the editor is placed on another jsp page and loaded through iframe, at the same time, the iframe's display = "none" should be triggered through an event.
Copy codeThe Code is as follows:
<Iframe src = "../common/editor. jsp" frameborder = "0" scrolling = "no" style = "margin: 0"
Width = "100%" height = "300" name = "zwFrame" id = "zwFrameId"> </iframe>
Since the original method does not work, I have to get it through jQuery. First of all, I want to read the content in "textarea", that is, contents (~~editor~#.html (), but this cannot be obtained. So I want to get the final result through obtaining the content in iframe, but I have not obtained it. Finally, I can view the final result through firefox debug:
From the figure above, we can see that to get the content "today's weather is good", we only need to get the content in the specified body.
Processing process: first obtain the iframe of the outermost layer, use iframe to obtain the iframe of the child element, and enter the layer to retrieve the body. As follows:
Copy codeThe Code is as follows:
Var editorText = ({{frames}'zwframe'{.doc ument). find ("iframe"). contents (). find ("body ");
Var contents = editorText.html ();
Contents (): searches for all child nodes (including text nodes) within the matching element ). If the element is an iframe, search for the document content.
The following provides several methods to obtain the Element Content in iframe:
Copy codeThe Code is as follows:
$ (Document. getElementsByTagName ("iframe" %%%0%.content%%document.body%.html ();
Display the content of the body element in iframe
Copy codeThe Code is as follows:
$ (Document. getElementById ("iframeId" pai.content?#document.body=.html ();
Obtain the content of the textarea element in iframe
Copy codeThe Code is as follows:
$ (Window. frames ["iframeName" cmd.doc ument). find ("# textareaId" cmd.html ();