Permission denied error when using "document.write" in the IE 8

4 posts, 0 answers
  1. Vitaliy
    Vitaliy avatar
    3 posts
    Member since:
    Aug 2012

    Posted 07 Sep 2012 Link to this post

    Hi,

    When I disable the RemoveScripts and EncodeScripts filters and paste the following javascript to the RAD editor:

    <script type="text/javascript">
    document.write('test');
    </script>

    I get the "Permission denied" error in the "telerik.web.ui.webresource.axd" file when using the IE 8 browser. In other browsers this script is successfully executed without any errors.

    Please provide me with a workaround and reason for this.

    Best regards,
    Vitaliy
  2. Rumen
    Admin
    Rumen avatar
    14324 posts

    Posted 10 Sep 2012 Link to this post

    Hi Vitaly,

    It is not a good idea to execute scripts in the content area of an editable iframe because this invoke side effects with the security of the browser, which cannot be avoided.

    What you can test is to render the content area of RadEditor as an editable div: ContentAreaMode="Div" property.


    Best regards,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. Vitaliy
    Vitaliy avatar
    3 posts
    Member since:
    Aug 2012

    Posted 12 Sep 2012 Link to this post

    Hi Rumen,

    Unfortunately, this did not resolve the issue. Is there any other solution?

    Best regards,
    Vitaliy
  4. Rumen
    Admin
    Rumen avatar
    14324 posts

    Posted 14 Sep 2012 Link to this post

    Hi,

    Unfortunately, we are not aware of any way to fix this issue. The problem is that the editor document is treated by the browser just like a normal web page. If there are scripts inside the page, we cannot stop the browser from executing them. This means that each time you go into edit mode, all scripts in the editor content will be executed and the content of the editor will be modified.

    I have a suggestion that we have not tested, but it might work for you. Instead of using document.write, insert a new element in the editor content, e.g. <div id="test"></div> and then set the content of this element with the script. This way the script will modify the same part of the content each time and you should have no problems with duplicated text.

    Another approach to to fix the problem you need to know when the script is inside the editor and if it is - do not write anything. For example:

    <script language=javascript type=text/javascript>
    if (typeof(MyEditorFlag)!='undefined')
    document.write('m' + 'ike'+'@'+'t'+'winharbor'+'.'+'com');
    </script>

    The above script checks for the existence of a special flag - MyEditorFlag. If the flag is not set, then the document.write call will not be executed. Of course, you need to define this flag on your page:

    <script type="text/javascript">
    var MyEditorFlag = true;
    </script>
    <RadE:RadEditor ...

    Since the IFRAME is considered as a different document, the flag will not be set there. Therefore, the script will only execute when it is not inside the editor content area (i.e. only in presentation mode). The only drawback from this approach is that if you click the "Preview" mode button in the editor, the script will not be executed, because it is still being considered inside the content area.

    Greetings,
    Rumen
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top