需要纯文本/ jQuery Javascript解决方案从文本区域清理Word HTML [英] Need Pure/jQuery Javascript Solution For Cleaning Word HTML From Text Area

查看:114
本文介绍了需要纯文本/ jQuery Javascript解决方案从文本区域清理Word HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经在这里被触及,但是我还没有找到适合我的情况的可行解决方案,所以我想,但是大脑信任回去工作,看看可以做些什么。

b
$ b

我有一个textarea,需要检测什么时候粘贴东西,并清除任何隐藏的HTML&引号。这个表单的内容通过电子邮件发送到第三方系统,这个系统特别拙劣,所以有时甚至将它编码为html实体字符也不会是一个安全的选择。



不幸的是,我不能使用像FCKEditor,TinyMCE等等,它必须在这个例子中保留常规的textarea。我试图从word函数中解析FCKEditor的粘贴,但没有运气跟踪它。



然而,如果需要,我可以使用jQuery库, t还没有找到一个jQuery插件。



我专门寻找适合清洁粘贴信息的信息,而不是如何监控内容变化的元素。



任何建设性的帮助将不胜感激。

解决方案

我看着David Archer的回答,他几乎回答它。我过去曾经使用类似于他的解决方案:
$ b $ pre code $(textarea)。change(function(){
//将任何开始和结束花括号转换为它们的HTML编码等价物
var strClean = $(this).val()。replace(/< / gi,'& lt;')。replace (/> / gi,'& gt;');

//删除任何双引号和单引号
strClean = strClean.replace(// gi,'' ).replace(/'/ gi,'');

//将数据重新放入
$(this).val(strClean);
});

如果您正在寻找完全删除HTML标记的方法

  $(textarea)。change(function(){
//完全去掉标签,取自原型库
var strClean = $(this).val()。replace(/< \ /?[^>] +> / gi,'');

//删除任何双引号和单引号。
strClean = strClean.replace(// gi,'').replace(/'/ gi,'');

// put数据返回。
$(this).val(strClean);
});


I know this issue has been touched on here but I have not found a viable solution for my situation yet, so I'd like to but the brain trust back to work and see what can be done.

I have a textarea in a form that needs to detect when something is pasted into it, and clean out any hidden HTML & quotation marks. The content of this form is getting emailed to a 3rd party system which is particularly bitchy, so sometimes even encoding it to the html entity characters isn't going to be a safe bet.

I unfortunately cannot use something like FCKEditor, TinyMCE, etc, it's gotta stay a regular textarea in this instance. I have attempted to dissect FCKEditor's paste from word function but have not had luck tracking it down.

I am however able to use the jQuery library if need be, but haven't found a jQuery plugin for this just yet.

I am specifically looking for information geared towards cleaning the information pasted in, not how to monitor the element for change of content.

Any constructive help would be greatly appreciated.

解决方案

I am looking at David Archer's answer and he pretty much answers it. I have used in the past a solution similar to his:

$("textarea").change( function() {
    // convert any opening and closing braces to their HTML encoded equivalent.
    var strClean = $(this).val().replace(/</gi, '&lt;').replace(/>/gi, '&gt;');

    // Remove any double and single quotation marks.
    strClean = strClean.replace(/"/gi, '').replace(/'/gi, '');

    // put the data back in.
    $(this).val(strClean);
});

If you are looking for a way to completely REMOVE HTML tags

$("textarea").change( function() {
    // Completely strips tags.  Taken from Prototype library.
    var strClean = $(this).val().replace(/<\/?[^>]+>/gi, '');

    // Remove any double and single quotation marks.
    strClean = strClean.replace(/"/gi, '').replace(/'/gi, '');

    // put the data back in.
    $(this).val(strClean);
});

这篇关于需要纯文本/ jQuery Javascript解决方案从文本区域清理Word HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆