开发者

Get an anchor in a ckeditor document

I am working with ckeditor and we build an custom plugin to define an link to an anchor on a page. Now when i try to get all the anchors on my page nothing is returned.

My HTML looks as follows:

<p>
    <a name="ancho开发者_JS百科r-anchor"></a></p>

But when I try to get all the anchors in the document like this:

editor.document.getElementsByTag("a")

nothing is returned. But when I place a normal anchor the above code will find that. Am I doing something wrong?

Regards!


This is straight from the link dialog:

    // Find out whether we have any anchors in the editor.
    // Get all IMG elements in CK document.
    var elements = editor.document.getElementsByTag( 'img' ),
        realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
        anchors = retval.anchors = [];

    for ( var i = 0; i < elements.count() ; i++ )
    {
        var item = elements.getItem( i );
        if ( item.data( 'cke-realelement' ) && item.data( 'cke-real-element-type' ) == 'anchor' )
            anchors.push( editor.restoreRealElement( item ) );
    }

    for ( i = 0 ; i < realAnchors.count() ; i++ )
        anchors.push( realAnchors.getItem( i ) );

    for ( i = 0 ; i < anchors.length ; i++ )
    {
        item = anchors[ i ];
        anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜