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
- <HTML >
-
- <HEAD >
-
- <title>ewebeditor: Standard invocation example </title >
-
- < META http-equiv=content-type Content ="text/html; charset=gb2312 ">
-
- < link rel=' stylesheet ' type = ' Text/css ' href = ' example.css ' >
-
- <script >
-
- function Validateform () {
-
-
- if (document.getElementById ("Content1"). value!= "") {
-
- document.getElementById ("MyForm"). Submit ();
-
- }else{
-
- alert ("Empty");
-
- }
-
- }
-
- </script >
-
- </HEAD >
-
- <BODY >
-
- < FORM method="Post " Name="MyForm" action="rs.jsp">
-
- < TABLE border="0" cellpadding ="2" cellspacing="1">
-
- <TR >
-
- <td> Edit content:</td>
-
- <TD >
-
- <INPUT type = "hidden" name = c9>"Content1" >
-
- <IFRAME ID = "EWebEditor1" src = ".. /ewebeditor.htm?id=content1&style=coolblue " frameborder=" 0 " scrolling = "no" width = " 550 " height="></IFRAME >
-
- </TD >
-
- </TR >
-
- <TR >
-
- < TD colspan= 2 align =right>
-
- < INPUT type= button Value="Commit" onclick="Validateform ()" >
-
- <INPUT type = reset value = "Refill">
-
- < INPUT type= button Value="View Source file" onclick="Location.replace (' View-source: ' +location) '>
-
- </TD >
-
- </TR >
-
- </TABLE >
-
- </FORM >
-
- </BODY >
-
- </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
- oform.attachevent ("onsubmit", Attachsubmit);
-
- if (! Oform.submiteditor) Oform.submiteditor = new Array ();
-
- Oform.submiteditor[oform.submiteditor.length] = attachsubmit;
-
- if (! Oform.originalsubmit) {
-
- oform.originalsubmit = Oform.submit;
-
- Oform.submit = function() {
-
- if (this. Submiteditor) {
-
- For (var i = 0; i < this. submiteditor.length; i++) {
-
- This . submiteditor[i] ();
-
- }
-
- }
-
- This . Originalsubmit ();
-
- }
-
- }
[JScript]View Plain Copy
- function attachsubmit () {
-
- var oform = olinkfield.form;
-
- if (!oform) {return;}
-
-
-
- var html = gethtml ();
-
- contentedit.value = html;
-
- if (scurrmode=="TEXT") {
-
- HTML = HTMLEncode (HTML);
-
- }
-
- Splittextfield (Olinkfield, HTML);
-
- }
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
- function validateform () {
-
- window.frames["EWebEditor1"]. Attachsubmit (); //Execute the Attachsubmit function in the IFRAME page
-
- if(document.getElementById ("Content1"). value!="" ){
-
- document.getElementById ("MyForm"). Submit ();
-
- }Else{
-
- alert ("Empty");
-
- }
-
- }
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
- var urlparams = new Object ();
-
- var aparams = document.location.search.substr (1). Split (' & ');
-
- For (i=0; i < aparams.length; i++) {
-
- var aparam = aparams[i].split (' = ');
-
- urlparams[aparam[0]] = aparam[1];
-
- }
-
-
-
- var slinkfieldname = urlparams["id"];
-
- var sextcss = urlparams["Extcss"];
-
- var sfullscreen = urlparams["fullscreen"];
-
-
-
- var config = new Object ();
-
- CONFIG. StyleName = (urlparams["style"])? urlparams["style"].tolowercase (): "CoolBlue";
-
- CONFIG. Cusdir = urlparams["Cusdir"];
-
- 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