Why does this Javascript inside a custom Button Function not work?

2 posts, 0 answers
  1. Yavuz Bogazci
    Yavuz Bogazci avatar
    7 posts
    Member since:
    Sep 2009

    Posted 27 Oct 2009 Link to this post

    Hi all,

    i have this custom Button function which works fine for me. Bu now i want to extend this function with one check. I want to check if the inserted Div already exists and stop processing.

    Here is my code:

    Telerik.Web.UI.Editor.CommandList["Inhaltsverzeichnis"] = function(commandName, editor, args)  
      if (document.getElementById("toc")) {   
        alert('Es existiert bereits ein Inhaltsverzeichnis-Tag im Content-Bereich!');  
      else {   
        editor.pasteHtml('Inhaltsverzeichnis<br /><br /><div id="toc">-Inhaltsverzeichnis-</div><br /><br />');   
        alert('Inhaltsverzeichnis wurde erfolgreich hinzugefuegt!');  

    The div with the id = toc definitly exists, but my code always goes to the Else part of the if statement. Whats wrong?

    thank you
  2. Stanimir
    Stanimir avatar
    1654 posts

    Posted 27 Oct 2009 Link to this post

    Hello Yavuz ,

    The reason for this issue is that you need to use the document object of the RadEditor and not the one of the page where the editor is loaded.

    For example:
    If you are using RadEditor for MOSS 4.x
    var doc  = editor.GetDocument();

    If you are using RadEditor for MOSS 5.x
    var doc  = editor.get_document();

    Kind regards,
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top