kindeditor链接添加SEO rel nofollow
kindeditor如何给链接添加SEO rel属性 nofollow不跟踪外链,效果如下图所示。
kindeditor版本为KindEditor 4.1.6,其他版本自己按照如下步骤修改源代码,主要是kindeditor-min.js的修改比较麻烦,压缩过的。
1)修改配置语言,下载压缩包 lang\zh_CN.js新增如下配置
'link.url' : 'URL', 'link.linkType' : '打开类型', 'link.rel' : '不跟踪链接',///////新增配置 'link.newWindow' : '新窗口',
2)plugins\link\link.js修改如下,添加链接seo属性rel=nofollow
/******************************************************************************* * KindEditor - WYSIWYG HTML Editor for Internet * Copyright (C) 2006-2011 kindsoft.net * * @author Roddy <luolonghao@gmail.com> * @site http://www.kindsoft.net/ * @licence http://www.kindsoft.net/license.php *******************************************************************************/ KindEditor.plugin('link', function(K) { var self = this, name = 'link'; self.plugin.link = { edit : function() { var lang = self.lang(name + '.'), html = '<div style="padding:20px;">' + //url '<div class="ke-dialog-row">' + '<label for="keUrl" style="width:60px;">' + lang.url + '</label>' + '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:260px;" /></div>' + //type '<div class="ke-dialog-row"">' + '<label for="keType" style="width:60px;">' + lang.linkType + '</label>' + '<select id="keType" name="type"></select>' + '</div>' + //follow////////////////SEO优化rel nofollow项 '<div class="ke-dialog-row"">' + '<label for="keType" style="width:60px;">' +( lang.rel||'nofollow') + '</label>' + '<input class="ke-input-text" type="checkbox" name="cbRel" />' + '</div>' + '</div>', dialog = self.createDialog({ name : name, width : 450, title : self.lang(name), body : html, yesBtn : { name : self.lang('yes'), click : function(e) { var url = K.trim(urlBox.val()); if (url == 'http://' || K.invalidUrl(url)) { alert(self.lang('invalidUrl')); urlBox[0].focus(); return; } self.exec('createlink', url, typeBox.val(), cbRel.checked).hideDialog().focus();//////////// } } }), div = dialog.div, urlBox = K('input[name="url"]', div), typeBox = K('select[name="type"]', div), cbRel = K('input[name="cbRel"]', div)[0];//////////////////// urlBox.val('http://'); typeBox[0].options[0] = new Option(lang.newWindow, '_blank'); typeBox[0].options[1] = new Option(lang.selfWindow, ''); self.cmd.selection(); var a = self.plugin.getSelectedLink(); if (a) { self.cmd.range.selectNode(a[0]); self.cmd.select(); urlBox.val(a.attr('data-ke-src')); typeBox.val(a.attr('target')); cbRel.checked = a.attr('rel') == 'nofollow'////////////////// } urlBox[0].focus(); urlBox[0].select(); }, 'delete' : function() { self.exec('unlink', null); } }; self.clickToolbar(name, self.plugin.link.edit); });
3)plugins\clearhtml\clearhtml.js修改,保留rel属性
/******************************************************************************* * KindEditor - WYSIWYG HTML Editor for Internet * Copyright (C) 2006-2011 kindsoft.net * * @author Roddy <luolonghao@gmail.com> * @site http://www.kindsoft.net/ * @licence http://www.kindsoft.net/license.php *******************************************************************************/ KindEditor.plugin('clearhtml', function(K) { var self = this, name = 'clearhtml'; self.clickToolbar(name, function() { self.focus(); var html = self.html(); html = html.replace(/(<script[^>]*>)([\s\S]*?)(<\/script>)/ig, ''); html = html.replace(/(<style[^>]*>)([\s\S]*?)(<\/style>)/ig, ''); html = K.formatHtml(html, { a : ['href', 'target','rel'],///////////保留rel属性,要不切换源代码时会被干掉这个属性 embed : ['src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess'], img : ['src', 'width', 'height', 'border', 'alt', 'title', '.width', '.height'], table : ['border'], 'td,th' : ['rowspan', 'colspan'], 'div,hr,br,tbody,tr,p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [] }); self.html(html); self.cmd.selection(true); self.addBookmark(); }); });
4)修改kindeditor-min.js,添加第2)步骤createlink参数nofollow,记事本打开kindeditor-min.js,搜索createlink,第一个出现的地方,修改createlink方法添加nofollow参数
//createlink:function(a,b){ //==>注意参数a,b不同版本可能不一样 createlink:function(a,b,nofollow){
在上面搜索完毕后继续搜索each关键字,找到下面类似代码添加红色标注的,添加/删除rel属性
5)保留创建a标签的rel属性,搜索,a:,然后属性数组添加rel属性
点击下载修改好的kindeditor-min.js及相关js文件
加支付宝好友偷能量挖...
原创文章,转载请注明出处:kindeditor链接添加SEO rel nofollow