简体   繁体   English

ckeditor 默认目标链接="_blank" 无法正常工作

[英]ckeditor default target link=“ _blank” not work properly

My ckeditor version is 4.4.7我的 ckeditor 版本是 4.4.7

I want to change the default target to every link of the text that I add to ckeditor and I found this code我想将默认目标更改为我添加到 ckeditor 的文本的每个链接,我找到了这段代码

 CKEDITOR.on('dialogDefinition', function(ev) { try { var dialogName = ev.data.name; var dialogDefinition = ev.data.definition; if (dialogName == 'link') { var informationTab = dialogDefinition.getContents('target'); var targetField = informationTab.get('linkTargetType'); targetField['default'] = '_blank'; } } catch (exception) { alert('Error ' + ev.message); } }); CKEDITOR.on('instanceReady', function(ev) { var editor = ev.editor, dataProcessor = editor.dataProcessor, htmlFilter = dataProcessor && dataProcessor.htmlFilter; htmlFilter.addRules({ a: function(element) { element.attributes['target'] = "_blank"; } }); });

I added this code to link.js file of ckeditor folder and it's working but not correctly我将此代码添加到 ckeditor 文件夹的 link.js 文件中,它工作正常但不正确

I mean if I copy the text that have a link from word to editor,it doesn't add target_blank to a href automatically我的意思是,如果我将具有从 word 链接到编辑器的文本复制,它不会自动将 target_blank 添加到 href

but I have to click 'edit link' on it and see the default target already on _blank但我必须点击它的“编辑链接”并查看 _blank 上已经存在的默认目标

在此处输入图片说明

then I click ok and save then it works.然后我点击确定并保存然后它就可以工作了。

but I want it to auto set target="_blank" on every link that I copy from word.但我希望它在我从 word 复制的每个链接上自动设置 target="_blank" 。

anyone can help?任何人都可以帮忙吗?

thanks.谢谢。

Where did you put your code?你把你的代码放在哪里?

I changed我变了

type : 'select',
id : 'linkTargetType',
label : commonLang.target,
'default' : 'notSet',

in _source\\plugins\\link\\dialogs\\link.js to_source\\plugins\\link\\dialogs\\link.js

type : 'select',
id : 'linkTargetType',
label : commonLang.target,
'default' : '_blank',

and this works fine.这很好用。

Editing inside plugin files is not an ideal solution.在插件文件中进行编辑并不是一个理想的解决方案。

The best solution would be to add this to your js file最好的解决方案是将其添加到您的 js 文件中

CKEDITOR.on( 'dialogDefinition', function( ev ) {
   var dialogName = ev.data.name;
   var dialogDefinition = ev.data.definition;
      if ( dialogName == 'link' ) {
          var targetTab = dialogDefinition.getContents( 'target' );
          var targetField = targetTab.get( 'linkTargetType' );
          targetField[ 'default' ] = '_blank';
      }
});

I added this code to link.js file of ckeditor folder and it's working but not correctly我将此代码添加到 ckeditor 文件夹的 link.js 文件中,它工作正常但不正确

You use this code directly on HTML page were you initialize the editor and not in link.js file:如果您初始化编辑器,而不是link.js文件中,您可以直接在 HTML 页面上使用此代码:

var editor = CKEDITOR.replace( 'editor1', { });
CKEDITOR.on('dialogDefinition', function(ev) {
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM