Hi,
I have created a plugin that creates or changes a hyperlink.
But I can't change the href attribute of an existing hyperlink, it remains unchanged.
Other attributes like "target" do change.
My code:
I have created a plugin that creates or changes a hyperlink.
But I can't change the href attribute of an existing hyperlink, it remains unchanged.
Other attributes like "target" do change.
My code:
(function(){ var a = { exec:function(editor){ var element = null; var selection = editor.getSelection(); if ( ( element = CKEDITOR.plugins.link.getSelectedLink( editor ) ) && element.hasAttribute( 'href' ) ) selection.selectElement( element ); if (!element) { // no problem here } else { // existing hyperlink element.setHtml ( 'Well that works' ); element.setAttributes ( { 'href' : 'mailto:from@button.com', 'target': '_blank' }); } } }, b='cmslink'; CKEDITOR.plugins.add(b,{ init:function(editor){ editor.addCommand(b,a); editor.ui.addButton('cmslink',{ label:'CMS hyperlink', icon: this.path + 'image.gif', command:b }); } }); })();
Re: element.setAttribute( 'href' , '#anything') won't apply
It looks like I found a solution myself.
it seems like adding a
element.removeAttribute ( '_cke_saved_href' );
after applying the attributes does the job
Copied from the code _source/plugins/link/dialogs/link.js.
The attribute '_cke_saved_href' seems to be holding the existing href attribute in this .js
In my plugin I don't use this attribute, so why delete it?
I haven't got a clue why, but it works.
Re: element.setAttribute( 'href' , '#anything') won't apply
Re: element.setAttribute( 'href' , '#anything') won't apply
Thanks a lot, saved me a lot of trouble