Need to get current tag by click editor content

4 posts, 1 answers
  1. Hariharan
    Hariharan avatar
    9 posts
    Member since:
    Nov 2011

    Posted 18 Nov 2011 Link to this post

    Hi All,

    I have a doubt regards get the tag name by click in editor content.
    In editor , i am able to get the tag name by the below method

    editor.attachEventHandler(

     

    "click", function (e) {

     

     

     

    alert(e.srcElement.nodeName);

     

     

    });

    But i need to get tag for below ,
    <Store>dfg fdg</Store>
    WHen i click inside / over the text "dfg fdg" (i.e.,Inside the editor content).i want to get the tage name "Store".Similar the node inspector.

    It working for only HTML tags.
    I know RadEditor is not xml Editor. But i need to get the custom tag.

    Is any possibility to get the current cursor position to find the text or Kindly explian detail what function done by click the cursor in editor content shows the breadcrumb in editor's footer (i.e., Store > )?

    Kindly expect your co-operation regards this ASAP.

     

  2. Answer
    Rumen
    Admin
    Rumen avatar
    14459 posts

    Posted 18 Nov 2011 Link to this post

    Hello Hariharan,

    Try the following code:

    Copy Code
    <script type="text/javascript">
        function OnClientLoad(editor, args) {
            var element = document.all ? editor.get_document().body : editor.get_document();
            $telerik.addExternalHandler(element, "click", function (e) {
                alert(editor.getSelectedElement().tagName);
            });
        }
    </script>
    <telerik:RadEditor runat="server" OnClientLoad="OnClientLoad" ID="RadEditor1">
        <Content><Store>dfg fdg</Store></Content>
    </telerik:RadEditor>


    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
  3. Hariharan
    Hariharan avatar
    9 posts
    Member since:
    Nov 2011

    Posted 18 Nov 2011 Link to this post

    Hello Rumen,

    Great thanks.

    My problem solved and am able to get the attribute for the tag.

    One more clarification on this, Is the script only works fine in IE9 and firefox ,chrome latest version?
    why i ask mean the script does works in IE8.

    Is any compatible issue..!
  4. Rumen
    Admin
    Rumen avatar
    14459 posts

    Posted 22 Nov 2011 Link to this post

    Hi Hariharan,

    This is IE8 browser related behavior with custom tags, which you can see with the code:

    <script type="text/javascript">
        function OnClientLoad(editor, args) {
            var element = document.all ? editor.get_document().body : editor.get_document();
            $telerik.addExternalHandler(element, "click", function (e) {
                var range = editor.get_document().selection.createRange();
                alert(range.parentElement().tagName);
            });
        }
    </script>
    <telerik:RadEditor runat="server" OnClientLoad="OnClientLoad" ID="RadEditor1">
        <Content>
            <Store>test</Store>
                <br/>
            <strong>test 2</strong>
        </Content>
    </telerik:RadEditor>
     
    To fix it provide a namespace for the custom tags as suggested in this MSDN article: Using Custom Tags in Internet Explorer, e.g.

    <my:Store>test</my:Store> 


    All the best,
    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