Javascript error in IE7 and IE8 when using Ajax to get Editor

Last post 03-21-2013, 8:58 AM by mwinata. 3 replies.
Sort Posts: Previous Next
  •  01-29-2013, 9:51 AM 76750

    Javascript error in IE7 and IE8 when using Ajax to get Editor

    I have an C# ASP.net page that adds the editor programmatically:

     

    protected void Page_Load(object sender, EventArgs e)

    {

          RTE.Editor ed = new RTE.Editor();

          ed.ID = "myEditor";

          Page.Controls.Add(ed);

    }

     

    This works fine in IE7 and IE8 when the page is called directly in the browser.

     

    If I try to Ajax the page, however, I get a Javascript error and the editor does not load:

     

    <html>

    <head>

    <title></title>

    <script type="text/javascript" src="/Assets/jquery/jquery.min.js"></script>

    <script type="text/javascript">

    $.post("getform.aspx",

          function (data) {  $('#pnl').html(data); });

    </script>

    </head>

    <body>

    <div id="pnl"></div>

    </body>

    </html>

     

    Error details:

     

    Line: 4

    Error: Unexpected call to method or property access.

     

    The debugger identifies this as a chunk of eval code.

    This is line 4:

     

    if(location.href.indexOf("://127.0.0.1")!=-1||location.href.indexOf("rtenocache")!=-1)

     

    Attempting to use the implicit "location" object is the issue.

    It is possible to access the "location" object explicitly in the debugger eg "window.location".

     

    This is a big problem for us, as most of our client-base use IE7.

     

    There is no bug in IE9, the editor loads successfully.

    Thanks


    Daniel Barratt

  •  01-29-2013, 2:18 PM 76753 in reply to 76750

    Re: Javascript error in IE7 and IE8 when using Ajax to get Editor

    Hi DanielBarratt,

     

    Can you send me the full code example page? So we can check it directly.

     

    Kenneth@CuteSoft.net

     

    Regards,

     

    Ken 

  •  02-01-2013, 10:38 AM 76775 in reply to 76753

    Re: Javascript error in IE7 and IE8 when using Ajax to get Editor

    Hi Ken,

     

    While preparing my reply, I discovered what was causing the problem.

     

    The aspx page which was returning the content to the AJAX request did not contain a standard ASP Form. The content returned was purely that generated by the server-side RTE.

     

    Once returned, the client-side RTE code dynamically adds a SCRIPT tag referencing the RTE "/richtexteditor/scripts/loader.js" file. IE7 and IE8 seem to require a valid form tag to be present in order to add this reference as a child to the FORM element. For some reason, IE9 did not require this.

     

    As adding this SCRIPT tag failed, the editor would not load.

     

    Simply adding a FORM tag to my ASPX page fixed the issue.

    Alternatively (as I do not want a FORM tag to be present), you can add the SCRIPT tag to the ASPX page, so not relying on it's dynamic creation on the client.

     

    Regards


    Dan

  •  03-21-2013, 8:58 AM 77079 in reply to 76775

    Re: Javascript error in IE7 and IE8 when using Ajax to get Editor

    Hi,

     

    I created a new aspx-page and load the Editor using the code you mentioned above:

    richtext.aspx 

    <script language="CS" runat="server">
                protected void Page_Load()
                {
                      RTE.Editor ed = new RTE.Editor();
                      ed.ID = "myEditor";
                      Page.Controls.Add(ed);
                }

    </script>

     

    with the Event RichTextEditor_OnLoad

          <script type='text/javascript'>
                function RichTextEditor_OnLoad(editor)
                {
                    editor.SetText("test123");
                    alert(editor._config.uniqueid);
                }
          </script>

     


    Then I try to embed the richtext.aspx on an existing page using this:

    $.post('otc_web/Framework/richtext.aspx', function(data) {
                        CurrentWindow.document.getElementById("richtext").innerHTML = data;
                        alert('Load was performed.');
                      });
     

    Editor is loaded correctly, but none of the Events (e.g. RichTextEditor_OnLoad) are called. But this happens only on the embedded page. Events are called upon opening richtext.aspx directly.

     

    I tried this on IE8 and IE9.

     

    Am I missing something here? Anyone has any idea why the Events are not triggered on the embedded page?

     

    Thanks in advance for any help! 

     

View as RSS news feed in XML