• 清除Fckeditor2.6.3 粘贴Word格式 弹出提示,并把word格式清除掉


    1.找到editor\js\fckeditorcode_ie.js
      找到if (confirm(FCKLang.PasteWordConfirm)){FCK.PasteFromWord();return false;}改为:
        var D=A;D=CleanWord(D,true,true);FCK.InsertHtml(D);return false;
    2.在fckeditorcode_ie.js最上面加上如下一个函数,Fckeditor2.6.3将会自动清除 Word格式,并保留一些布局,比如table标签等将不会清除

    掉,也不再弹出提示"是否清除word格式"
      function CleanWord( oNode, bIgnoreFont, bRemoveStyles )
    {
     //var html = oNode.innerHTML ;
         var html=oNode;
     html = html.replace(/<o:p>\s*<\/o:p>/g, '') ;
     html = html.replace(/<o:p>.*?<\/o:p>/g, '&nbsp;') ;

     // Remove mso-xxx styles.
     html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, '' ) ;

     // Remove margin styles.
     html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, '' ) ;
     html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;

     html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, '' ) ;
     html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;

     html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;

     html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;

     html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;

     html = html.replace( /\s*tab-stops:[^;"]*;?/gi, '' ) ;
     html = html.replace( /\s*tab-stops:[^"]*/gi, '' ) ;

     // Remove FONT face attributes.
     if ( bIgnoreFont )
     {
      html = html.replace( /\s*face="[^"]*"/gi, '' ) ;
      html = html.replace( /\s*face=[^ >]*/gi, '' ) ;

      html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, '' ) ;
     }

     // Remove Class attributes
     html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;

     // Remove styles.
     if ( bRemoveStyles )
      html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;

     // Remove empty styles.
     html =  html.replace( /\s*style="\s*"/gi, '' ) ;

     html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;

     html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;

     // Remove Lang attributes
     html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;

     html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;

     html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;

     // Remove XML elements and declarations
     html = html.replace(/<http://www.cnblogs.com/ggbbeyou/admin/file:///?\?xml[^>]*>/gi, '' ) ;

     // Remove Tags with XML namespace declarations: <o:p><\/o:p>
     html = html.replace(/<\/?\w+:[^>]*>/gi, '' ) ;

     // Remove comments [SF BUG-1481861].
     html = html.replace(/<\!--.*?-->/g, '' ) ;

     html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

     html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

     // Remove "display:none" tags.
     html = html.replace( /<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none(.*?)<\/\1>/ig, '' ) ;

     // Remove language tags
     html = html.replace( /<(\w[^>]*) language=([^ |>]*)([^>]*)/gi, "<$1$3") ;

     // Remove onmouseover and onmouseout events (from MS Word comments effect)
     html = html.replace( /<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi, "<$1$3") ;
     html = html.replace( /<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi, "<$1$3") ;

     if ( FCKConfig.CleanWordKeepsStructure )
     {
      // The original <Hn> tag send from Word is something like this: <Hn style="margin-top:0px;margin-bottom:0px">
      html = html.replace( /<H(\d)([^>]*)>/gi, '<h$1>' ) ;

      // Word likes to insert extra <font> tags, when using MSIE. (Wierd).
      html = html.replace( /<(H\d)><FONT[^>]*>(.*?)<\/FONT><\/\1>/gi, '<$1>$2<\/$1>' );
      html = html.replace( /<(H\d)><EM>(.*?)<\/EM><\/\1>/gi, '<$1>$2<\/$1>' );
     }
     else
     {
      html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
      html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
      html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
      html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
      html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
      html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;

      html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;

      // Transform <P> to <DIV>
      var re = new RegExp( '(<P)([^>]*>.*?)(<\/P>)', 'gi' ) ; // Different because of a IE 5.0 error
      html = html.replace( re, '<div$2<\/div>' ) ;

      // Remove empty tags (three times, just to be sure).
      // This also removes any empty anchor
      html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
      html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
      html = html.replace( /<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g, '' ) ;
     }

     return html ;
    }

  • 相关阅读:
    微信公众号 发送客服消息
    juqery 点击谁获取他的值,赋给input标签
    微信执行退出页面,直接回到微信对话窗口
    微信jssdk上传图片,一张一张的上传 和 一次性传好几张
    juqery 判断所有input 不能为空 判断只能为数字 判断身份证号:18位和15位 判断是否银行卡号
    php foreach
    现在越来越喜欢用ajax传值了,这样能让网站的体验性很好,今天就总结了一下常用的
    有时候不用explode截取字符串了,可以用用substr()
    ztree 文件夹类型的 树状图
    POJ 1065 Wooden Sticks
  • 原文地址:https://www.cnblogs.com/ggbbeyou/p/1605358.html
Copyright © 2020-2023  润新知