Wrong <SCRIPT/> tag formatting

Last post 11-22-2011, 9:54 AM by Herev. 7 replies.
Sort Posts: Previous Next
  •  11-20-2011, 10:15 AM 71544

    Wrong <SCRIPT/> tag formatting

    Hi,
     
    I have CuteEditor for .Net version 6.6. Browser - IE8. EnableStripScriptTags property is set to false. In the editor I create a simple HTML page with the following code:
     
    <HTML>
        <HEAD>
          <SCRIPT>
             function test() // simply a test function
             { alert("Hello!");
             }
          </SCRIPT>
        </HEAD>
        <BODY onload="test()">
        </BODY>
    </HTML>
     
    After calling getHTML() I'm getting the HTML code correctly. But when I call setHTML() with the same code, I get the following wrongly formatted HTML in the editor:
     
    <HTML>
        <HEAD>
            <SCRIPT>         function test() // simply a test function         { alert("Hello!");         }      </SCRIPT>
        </HEAD>
        <BODY onload=test()>
        </BODY>
    </HTML>
     
    As you can see CuteEditor removes new lines from the code inside <SCRIPT/> tag, as the result the JavaScript code is distorted.
     
    Can you please help me with this issue?
     
    Filed under:
  •  11-21-2011, 6:07 AM 71551 in reply to 71544

    Re: Wrong <SCRIPT/> tag formatting

    Hi Herev,
     
    If you set it as the code below, that should be the correct behavior. Because your content in the same line, so editor set it as the same line.
     
    function setContent()
    {
        var editor1=document.getElementById("<%= editor1.ClientID %>");
        var s="<script>alert('111');// simply a test function</"+"script>";
        editor1.SetHTML(s);
    }
     
    Try the example below, it shows you how to use the line break to avoid it.
     
    <%@ Page Language="C#" AutoEventWireup="true" %>

    <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    </head>
    <body>
        <form id="form1" runat="server">
            <CE:Editor ID="editor1" runat="server" EditCompleteDocument="true" EnableStripScriptTags="false">
            </CE:Editor>
            <input type="button" value="Set html" onclick="setContent()" />
        </form>
    </body>
    </html>

    <script>
    function setContent()
    {
        var editor1=document.getElementById("<%= editor1.ClientID %>");
        var s="<script>alert('111');"+"//simply a test function\n</"+"script>";
        editor1.SetHTML(s);
           
    }
    </script>
     
    Regards,
     
    Ken
  •  11-21-2011, 6:50 AM 71553 in reply to 71551

    Re: Wrong <SCRIPT/> tag formatting

    Hi Ken,

    Thank you for your quick answer, bu I probably didn't explain my problem clearly enough.
    So here are the steps I do to reproduce the problem:

    1. Open CuteEditor.
    2. Press HTML button on the bottom of the editor.
    3. Enter HTML code containing JavaScript function as described in my previous post.
    3. Call getHTML() API function and get HTML content as a string.
    4. Save the string received from getHTML() in my database.
    5. Close CuteEditor.
    6. Open CuteEditor again.
    7. Get the string from the database and call setHTML() API with this string as parameter.

    I expect that the string I got from getHTML() will restore exactly the same HTML when transferred to setHTML(), but it doesn't happen.
    Where am I mistaken?

    Thank you again for your help,

    Herev

  •  11-21-2011, 7:05 AM 71554 in reply to 71553

    Re: Wrong <SCRIPT/> tag formatting

    Addition.
    Here is the code of my ASPX page:
     

    <%@ Page Language="C#"%>
    <%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>
    <html>
        <head>
          <title>Novaview HTML editor</title>
          <link rel="stylesheet" href="style.css" type="text/css" />
          <script language="JavaScript" type="text/javascript" >

         function getHtml()
         {   // get the cute editor instance
            var editor1 = document.getElementById('<%=Editor1.ClientID%>');          
            // Get the editor HTML
            return(editor1.getHTML());
         }  
       
         function setHtml(html)
         {   // get the cute editor instance
            var editor1 = document.getElementById('<%=Editor1.ClientID%>');

            if(!editor1 || !editor1.IsReady)
            { window.setTimeout("setHtml('"+html+"')",100);
              return;
            }
        
          // Set the editor
          editor1.setHTML(html);
        }

           </script>   
        </head>
        <body>
         <form runat="server">
          <span style="position:absolute;width:100%;height:100%">
             <CE:Editor id="Editor1" FullPage="True" Focus="True" AllowPasteHtml="False" EditCompleteDocument="True" EnableStripScriptTags="False" EnableStripIframeTags="False" EnableStripLinkTagsCodeInjection="False" EnableStripStyleTagsCodeInjection="False"  ConvertHTMLTagstoLowercase="False" EditorWysiwygModeCss="style.css" runat="server"></CE:Editor>
          </span>
         </form>
        </body>
    </html>

    <script runat="server">
             void Page_Load(object sender, System.EventArgs e)
             {  Editor1.AutoConfigure  = AutoConfigure.Full;
                 Editor1.ResizeMode = EditorResizeMode.None;        
                 Editor1.RemoveTBODYTag = true;
                 Editor1.EditorOnPaste = PasteBehavior.PasteAsHTML;
             } 
    </script>

  •  11-22-2011, 7:22 AM 71577 in reply to 71554

    Re: Wrong <SCRIPT/> tag formatting

    Hi Herev,
     
    I tried save the content into the  HiddenField control, it still works fine for me.
     
    Below is my test example
    <%@ Page Language="C#" AutoEventWireup="true" %>

    <%@ Register Assembly="CuteEditor" Namespace="CuteEditor" TagPrefix="CE" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
    </head>
    <body>
        <form id="form1" runat="server">
            <CE:Editor ID="editor1" runat="server" EditCompleteDocument="true" EnableStripScriptTags="false">
            </CE:Editor>
            <asp:HiddenField ID="hf1" runat="server" />
            <input type="button" value="get html" onclick="getContent()" />
            <input type="button" value="Set html" onclick="setContent()" />
        </form>
    </body>
    </html>

    <script>
       var hf1=document.getElementById("<%= hf1.ClientID %>");
    function setContent()
    {
      var editor1=document.getElementById("<%= editor1.ClientID %>");
       editor1.SetHTML("");
       editor1.SetHTML(hf1.value);
          
    }
    function getContent()
    {
       var editor1=document.getElementById("<%= editor1.ClientID %>");
       hf1.value=editor1.getHTML();
     
    }
    </script>
     
     
    Test steps
     
    1. Run the page then paste the code below into html view
     
    <script>
    alert('111');//simply a test function
    </script>
     
    2.  Click the get content button, then the html code will save into the HiddenField
     
    3.  Click the  set content button. editor will clean the old text then set the HiddenField value which get from the getHTML() API into editor again.
     
    I thought that should be same as the content save into the database right?
     
    Regards,
     
    Ken
     
  •  11-22-2011, 8:04 AM 71579 in reply to 71544

    Re: Wrong <SCRIPT/> tag formatting

    Hi Ken,

     

    Everything is correct, except of the script you're trying to enter.

    The problem is that if the script has multiple lines of code, after you restore it with setHTML(),

    it will be put into one single line. Except of bad readability, if the script contains comments which

    start from //, the script will be distorted – all the script lines after // will be commented.

    Try to put the following script into your HTML:

     

    <SCRIPT>

        function test() // simply a test function

         { alert("Hello!");

         }

     </SCRIPT>

     

    You’ll see that after calling setHTML() you’ll get something like this:

     

    <SCRIPT>        function test() // simply a test function        { alert("Hello!");        }     </SCRIPT>

     

    As you understand, this code is not valid.

     

    Thanks,

     

    Herev

  •  11-22-2011, 8:49 AM 71582 in reply to 71579

    Re: Wrong <SCRIPT/> tag formatting

    Hi Herev,
     
    I tested my example page with your code, it works fine for me too.
     
    Regards,
     
    Ken
  •  11-22-2011, 9:54 AM 71584 in reply to 71582

    Re: Wrong <SCRIPT/> tag formatting

    Hi Ken,
     
    I found the problem, it really was in our part.
    Thank you a lot for your help.
     
    Herev
View as RSS news feed in XML