Javascript 从word复制、粘贴到Microsoft编辑和删除word标记
我尝试从MS Word复制文本并将其粘贴到我的web应用程序上的niceditor中,它的格式基于MS Word格式。Javascript 从word复制、粘贴到Microsoft编辑和删除word标记,javascript,ms-word,nicedit,Javascript,Ms Word,Nicedit,我尝试从MS Word复制文本并将其粘贴到我的web应用程序上的niceditor中,它的格式基于MS Word格式。 如果要删除所有编辑,我需要先删除文本上的文字格式,然后再将内容保存到niceeditor中。将内容粘贴到记事本中,然后粘贴到niceeditor。谢谢各位,我从谷歌找到了解决方案。解决方案是,在nicEdit插件中更改特定类 在nicedit.js文件中替换nicEditorInstance,如下所示 var nicEditorInstance=bkClass.extend(
如果要删除所有编辑,我需要先删除文本上的文字格式,然后再将内容保存到niceeditor中。将内容粘贴到记事本中,然后粘贴到niceeditor。谢谢各位,我从谷歌找到了解决方案。解决方案是,在nicEdit插件中更改特定类 在nicedit.js文件中替换nicEditorInstance,如下所示
var nicEditorInstance=bkClass.extend({
选:错,
构造:函数(e、选项、编辑){
this.ne=nicEditor;
this.elm=this.e=e;
this.options=options |{};
newX=parseInt(e.getStyle('width'))| | e.clientWidth;
newY=parseInt(e.getStyle('height'))| | e.clientHeight;
此参数为0.initialHeight=newY-8;
var isTextarea=(e.nodeName.toLowerCase()=“textarea”);
if(isTextarea | | this.options.hasPanel){
变量ie7s=(bkLib.isMSIE&&!((typeof document.body.style.maxHeight!=“未定义”)&&document.compatMode==“CSS1Compat”))
var s={width:newX+'px',border:'2px solid#f1f1',borderTop:0,overflowY:'auto',overflowX:'hidden'};
s[(ie7s)?'height':'maxHeight']=(this.ne.options.maxHeight)?this.ne.options.maxHeight+'px':空;
this.editorContain=新的bkElement('DIV').setStyle(s).在(e)之前追加;
/*清洁字粘贴模块*/
//var editorElm=new bkElement('DIV').setAttributes({id:e.id}).setStyle({width:(newX-8)+'px',margin:'4px',minHeight:newY+'px').addClass('main').appendTo(this.editorContain);
var editorElm=new bkElement('DIV').setStyle({width:(newX-8)+'px',margin:'4px',minHeight:newY++'px'}).addClass('main').appendTo(this.editorContain);
e、 setStyle({display:'none'});
editorElm.innerHTML=e.innerHTML;
if(isTextarea){
editorElm.setContent(e.value);
this.copyElm=e;
var f=e.parentTag('FORM');
如果(f){bkLib.addEvent(f,'submit',this.saveContent.closure(this));}
}
setStyle((ie7s){height:newY+'px'}:{overflow:'hidden'});
this.elm=editorElm;
}
this.ne.addEvent('blur',this.blur.closure(this));
this.init();
这个。blur();
},
init:function(){
this.elm.setAttribute('contentEditable','true');
if(this.getContent()==“”){
此.setContent(“
”);
}
this.instanceDoc=document.defaultView;
this.elm.addEvent('mousedown',this.selected.closureListener(this)).addEvent('keypress',this.keyDown.closureListener(this)).addEvent('focus',this.selected.closure(this)).addEvent('blur',this.blur.closure(this));
this.ne.firevent('add',this);
/*清洁字粘贴模块*/
this.elm.addEvent('paste',this.initPasteClean.closureListener(this));
},
initPasteClean:函数(){
this.pasteCache=this.getElm().innerHTML;
setTimeout(this.pasteClean.closure(this),100);
},
/*CLEAN WORD PASTE MOD:为CLEAN WORD PASTE添加了pasteClean方法*/
粘贴清理:函数(){
var matchedHead=“”;
var matchedTail=“”;
var newContent=this.getElm().innerHTML;
this.ne.firevent(“get”,this);
var newContentStart=0;
var newContentFinish=0;
var newSnippet=“”;
var tempNode=document.createElement(“div”);
/*查找匹配的两个字符串的开头*/
for(newContentStart=0;newContent.charAt(newContentStart)==this.pasteCache.charAt(newContentStart);newContentStart++)
{
matchedHead+=this.pasteCache.charAt(newContentStart);
}
/*如果newContentStart位于HTML标记内,请移动到标记的左括号*/
对于(var i=newContentStart;i>=0;i--)
{
if(this.pasteCache.charAt(i)==“”)
{
打破
}
}
newContent=this.reverse(newContent);
this.pasteCache=this.reverse(this.pasteCache);
/*查找匹配的两个字符串的结尾*/
for(newContentFinish=0;newContent.charAt(newContentFinish)==this.pasteCache.charAt(newContentFinish);newContentFinish++)
{
matchedTail+=this.pasteCache.charAt(newContentFinish);
}
/*如果newContentFinish位于HTML标记内,则移动到标记的右括号*/
对于(var i=newContentFinish;i>=0;i--)
{
if(this.pasteCache.charAt(i)=“>”)
{
newContentFinish=i;
matchedTail=this.pasteCache.substring(0,newContentFinish);
打破
}
else if(this.pasteCache.charAt(i)=“]*>/g,”);
newSnippet=newSnippet.replace(/]+:[^>]*>/g,”);
newSnippet=newSnippet.replace(/]+:[^>]*>/g,”);
/*删除想要的标签*/
newSnippet=newSnippet.replace(//gi',);
this.content=matchedHead+newSnippet+matchedTail;
本。ne。火灾事件(“设置”,本);
this.elm.innerHTML=this.content;
},
反向:函数(sentString){
var theString=“”;
对于(var i=sentString.length-1;i>=0;i--){
字符串+=sentString.charAt(i);
}
返回字符串;
},
/*CLEAN WORD PASTE MOD:为CLEAN WORD PASTE添加了validTags方法*/
validTags:函数(代码段){
var theString=snippet;
/*将大写元素名称替换为小写*/
字符串=字符串.replace(/]*/g,函数(match){返回match.toLowerCase();});
/*将大写属性名称替换为小写*/
字符串=theString.repla