从网页上复制内容的时候自动清除代码

3:27 pm CMSWare

很多时候录文章都是要从别的网页上复制粘贴,虽然cmsware提供了清除HTML代码的按钮,但是显然这个不适用于懒人。所以能在复制的时候就清除掉就好了。
最开始我打算在onpaste这个javascript事件上做文章,后来发现这个几乎是不可能的任务,因为不止是粘贴,很多操作,比如撤销、恢复等等等等都要用上这个事件。

找到“if(el.frameWindow.event.ctrlKey) ”的判断,在下面的一堆else if中添加
else if(el.frameWindow.event.keyCode == 86) {//V
pasteWord()
}

意思很明白了,就是如果之前按下的键是Ctrl+V,就调用pasteWord函数

然后打开同目录下的toolbar.php,找到<tr id=cmPaste
把后面的onClick事件改成’window.parent.doCommand(“Paste”);parent.oPopup2.hide()’,之前它的命令是parent.document.execCommand(“Paste”),是直接去让javascript执行Paste,而改了以后则去执行上面第二步中我们修改过的函数,这样就OK了。

另:cmsware论坛的xinpengok写了个加强版HTML清除代码,有兴趣的朋友不妨看看

One Response

  1. cmsware让默认的新闻编辑器增加清除多余的html功能 « iammecn Says:

    [...] 今天看到http://blog.98xx.com/zleaf/?p=68 的博客,他这里为默认编辑器增加了一个自动清除多余html的功能,但并不适用了新闻编辑器,所以我改了一下,参考了http://www.lonmo.com/bbs/read.php?tid=10605的函数. [...]

Leave a Comment

Your comment

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.