This is a migrated thread and some comments may be shown as answers.

Need to get current tag by click editor content

3 Answers 65 Views
Editor
This is a migrated thread and some comments may be shown as answers.
Hariharan
Top achievements
Rank 1
Hariharan asked on 18 Nov 2011, 07:47 AM
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.

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Rumen
Telerik team
answered on 18 Nov 2011, 04:29 PM
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
0
Hariharan
Top achievements
Rank 1
answered on 19 Nov 2011, 04:49 AM
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..!
0
Rumen
Telerik team
answered on 22 Nov 2011, 03:45 PM
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
Tags
Editor
Asked by
Hariharan
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Hariharan
Top achievements
Rank 1
Share this question
or