How to use JS to get the content of Ewebeditor editor

Source: Internet
Author: User

Using JavaScript to take control of the value of the original is a simple thing is ewebeditor made very inconvenient, leading to a lot of beginners, do not know how to get. Write our habitual method of value before analyzing it.

[HTML]View Plain Copy
  1. <HTML >
  2.   
  3. <HEAD >
  4.   
  5. <title>ewebeditor: Standard invocation example </title >
  6.   
  7. < META http-equiv=content-type Content  ="text/html; charset=gb2312 ">
  8.   
  9. < link rel=' stylesheet ' type = ' Text/css ' href = ' example.css ' >
  10.   
  11. <script >
  12.   
  13. function Validateform () {
  14.   
  15.   
  16. if (document.getElementById ("Content1"). value!= "") {
  17.   
  18. document.getElementById ("MyForm"). Submit ();
  19.   
  20. }else{
  21.   
  22. alert ("Empty");
  23.   
  24.         }  
  25.   
  26.     }  
  27.   
  28. </script >
  29.   
  30. </HEAD >
  31.   
  32. <BODY >
  33.   
  34. < FORM method="Post " Name="MyForm" action="rs.jsp">   
  35.   
  36. < TABLE border="0" cellpadding ="2" cellspacing="1">
  37.   
  38. <TR >
  39.   
  40. <td> Edit content:</td>   
  41.   
  42. <TD >
  43.   
  44. <INPUT type = "hidden" name = c9>"Content1" >
  45.   
  46. <IFRAME ID = "EWebEditor1" src = ".. /ewebeditor.htm?id=content1&style=coolblue " frameborder=" 0 " scrolling = "no" width = " 550 " height="></IFRAME >
  47.   
  48. </TD >
  49.   
  50. </TR >
  51.   
  52. <TR >
  53.   
  54. < TD colspan= 2 align =right>
  55.   
  56. < INPUT type= button Value="Commit" onclick="Validateform ()" >    
  57.   
  58. <INPUT type = reset value = "Refill">
  59.   
  60. < INPUT type= button Value="View Source file" onclick="Location.replace (' View-source: ' +location) '>
  61.   
  62. </TD >
  63.   
  64. </TR >
  65.   
  66. </TABLE >
  67.   
  68. </FORM >
  69.   
  70. </BODY >
  71.   
  72. </HTML >

The above code is very simple. We generally think of document.getElementById ("Content1"). Value so it can be value, but in fact it is not so, in this way, the value can only be taken to the initial value, when the content of the editor is not available, Why is it? Why the daemon can get the value in the editor, <%=request.getparameter ("Content1")%> here is the content that can be taken to the editor, but document.getElementById (" Content1 "). Value is not allowed. It seems ewebeditor in JS in the hands and feet, must be dynamic to help set the commit event, or dynamically bound in the source code search onsubmit found the following codes, the original dynamic binding onsubmit event, so that each time before committing to execute Attachsubmit function

[JScript]View Plain Copy
  1. oform.attachevent ("onsubmit", Attachsubmit);
  2.   
  3. if (! Oform.submiteditor) Oform.submiteditor = new Array ();
  4.   
  5. Oform.submiteditor[oform.submiteditor.length] = attachsubmit;
  6.   
  7. if (! Oform.originalsubmit) {
  8.   
  9. oform.originalsubmit = Oform.submit;
  10.   
  11. Oform.submit = function() {
  12.   
  13. if (this. Submiteditor) {
  14.   
  15. For (var i = 0; i < this. submiteditor.length; i++) {
  16.   
  17. This . submiteditor[i] ();
  18.   
  19.             }  
  20.   
  21.         }  
  22.   
  23. This . Originalsubmit ();
  24.   
  25.     }  
  26.   
  27. }  
[JScript]View Plain Copy
  1. function attachsubmit () {
  2.   
  3. var oform = olinkfield.form;
  4.   
  5. if (!oform) {return;}
  6.   
  7.       
  8.   
  9. var html = gethtml ();
  10.   
  11. contentedit.value = html;
  12.   
  13. if (scurrmode=="TEXT") {
  14.   
  15. HTML = HTMLEncode (HTML);
  16.   
  17.     }  
  18.   
  19. Splittextfield (Olinkfield, HTML);
  20.   
  21. }  

Attachsubmit is the process of the copy Editor's contents into a hidden field control.

Knowing the process our problems will not be difficult to solve. Simply perform the next attachsubmit before fetching the editor content

[JScript]View Plain Copy
  1. function validateform () {
  2.   
  3. window.frames["EWebEditor1"]. Attachsubmit (); //Execute the Attachsubmit function in the IFRAME page   
  4.   
  5. if(document.getElementById ("Content1"). value!="" ){  
  6.   
  7. document.getElementById ("MyForm"). Submit ();
  8.   
  9. }Else{
  10.   
  11. alert ("Empty");
  12.   
  13.     }  
  14.   
  15. }  

The whole process is over, in fact, many ideas in the Ewebeditor code are very valuable, such as the Attachsubmit binding Submit method of the re-encapsulation, I also found a relatively good writing code is also posted together.

[JScript]View Plain Copy
  1. var urlparams = new Object ();
  2.   
  3. var aparams = document.location.search.substr (1). Split (' & ');
  4.   
  5. For (i=0; i < aparams.length; i++) {
  6.   
  7. var aparam = aparams[i].split (' = ');
  8.   
  9. urlparams[aparam[0]] = aparam[1];
  10.   
  11. }  
  12.   
  13.   
  14.   
  15. var slinkfieldname = urlparams["id"];
  16.   
  17. var sextcss = urlparams["Extcss"];
  18.   
  19. var sfullscreen = urlparams["fullscreen"];
  20.   
  21.   
  22.   
  23. var config = new Object ();
  24.   
  25. CONFIG. StyleName = (urlparams["style"])?  urlparams["style"].tolowercase (): "CoolBlue";
  26.   
  27. CONFIG.  Cusdir = urlparams["Cusdir"];
  28.   
  29. CONFIG.  Serverext = "jsp";

Parsing URL method, this method before Koko told me once, today in Ewebeditor see again, it seems to be a more general method of parsing URL parameters.

Summary: In fact, Ewebeditor just modified the submission form of the two events, before submitting the form to the value of copy, so as to avoid the editor every time the synchronization value of this unnecessary operation.

How to use JS to get the contents of the Ewebeditor editor

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.