Javascript File and iFrame

5 posts, 0 answers
  1. Joe Hakooz
    Joe Hakooz avatar
    65 posts
    Member since:
    Dec 2007

    Posted 24 Mar 2008 Link to this post

    Hi,
    How can I attach a JS file to the iframe of the editor so that I can include javascript calls in my content? 

    For example, I have a simple "show/hide div" javascript function in a file called scripts.js. I have content, managed via the editor, that contains the following HTML:
    <a href="#" onclick="toggle_visibility('foo');">CLICK HERE</a>
    <div id="foo" style="DISPLAY: none">MY CONTENT</div>
    This code simply shows or hides the div named "foo".

    The problem is that when editing the HTML in the editor, the page quickly displays a javascript error, breaking the editor. My best guess is that the iframe used by the editor cannot see the linked JS file. So it seems that attaching the JS file to the editor or iframe somehow would solve this.

    Make sense?
    Thanks for any help,
    Joe
  2. Rumen
    Admin
    Rumen avatar
    12848 posts

    Posted 28 Mar 2008 Link to this post

    Hi Joe,

    You can achieve your scenario using the solution below that imports the external js code in the editor's content area:

        <script id="PageJavaScript" language="javascript" type=text/javascript>
        function test1()
        {
            alert("test");
        }
        function test2()
        {
            alert("test2");
        }
        </script>   
    </head>
    <body>
    <script type="text/javascript">
    function OnClientLoad(editor, sender)
    {
        var oPageScript = document.getElementById("PageJavaScript");
        var filter  = editor.get_FiltersManager();
        filter.getFilterByName("EncodeScriptsFilter").Enabled = false;
                                       
        var oScript  = "<script defer='false'>\n" + oPageScript.innerHTML + "\n</" + "script>";   
        editor.setFocus();
        alert(editor);
        editor.set_html(editor.get_html(true) + oScript);
    }
    </script>

    <form id="Form1" method="post" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <telerik:RadEditor ID="RadEditor1" AllowScripts="true" OnClientLoad="OnClientLoad" runat="server">
        <Content>
            <img onmouseover="test1();" onmouseout="test2();" src="http://www.telerik.com/r.a.d.controls/Editor/Img/productBox.gif">               
        </Content>
    </telerik:RadEditor>

    Feel free to modify and enhance the solution to fit your scenario.

    Best wishes,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joe Hakooz
    Joe Hakooz avatar
    65 posts
    Member since:
    Dec 2007

    Posted 29 Mar 2008 Link to this post

    Thanks Rumen.

    After applying your solution, it appears that was not my problem after all...

    Tested in both IE 6, and Firefox 2, with or without JS calls in the content:
    After saving content (postback) the editor gives a JS error fairly frequently when I try to save a second time. I'd say 50% of the time. Here are the two JS errors produced.

    Line: 23 _gel("GM71statusmsg") has no properties
    Line: 5210 _bf.contentWindow has no properties

    Is this a known issue? And if so, any work around?

    Thanks
  5. Rumen
    Admin
    Rumen avatar
    12848 posts

    Posted 31 Mar 2008 Link to this post

    Hi Joe,

    I am not aware of such a problem.

    Could you please open a support ticket and send me a sample running project that demonstrates the reported problem? I want to reproduce the issue on my side and examine your code.

    After that I will see what is causing the problem and try to provide a solution.

    Best regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Joe Hakooz
    Joe Hakooz avatar
    65 posts
    Member since:
    Dec 2007

    Posted 31 Mar 2008 Link to this post

    I have several pages that use the editor and I'm only seeing this issue on a few of them. I'll investigate a little further and if I can't resolve it I'll open a ticket.

    Thanks Rumen,
    Joe
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017