getData HTML格式??? [英] getData HTML format???

查看:194
本文介绍了getData HTML格式???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

在我们的网站上,我们有一个允许用户复制和粘贴的部分或者

将(几乎任何)网页的内容拖放到一个Div。

我需要访问剪贴板数据。要做到这一点,我正在使用

..getData()函数。问题是,我只能访问''Text''和''URL''

格式。我想要一个HTML格式。原因是

我想在粘贴

内容之前在剪贴板中做一些文本替换。

1 )是否有可能以HTML格式获取剪贴板数据?

2)如果不可能,是否可以使用其他方法(或事件)

我可能是在粘贴之前不知道要改变内容吗?

Hi all,
On our site we have a section that allows users to copy and paste or
drag and drop the contents of (pretty much any) webpage into a Div.
I need to get access to the clipboard data. To do this I''m using the
..getData() function. Problem is, I only have access to ''Text'' and ''URL''
formats. I''d like to have an HTML format. The reason for this is that
I''d like to do some text replacements in the clipboard before the
contents are pasted.
1) Is it possible to get the clipboard data in HTML format?
2) If not possible, is it possible to use some other method (or event)
I may be unaware of to alter the contents before they are pasted?

推荐答案

nAmYzArC在2005年12月19日下午4:00说了以下内容:
nAmYzArC said the following on 12/19/2005 4:00 PM:
大家好,
在我们的网站上,我们有一个部分允许用户复制和粘贴或者将(几乎任何)网页的内容拖放到Div中。
我需要访问剪贴板数据。要做到这一点,我正在使用
..getData()函数。


只有IE允许访问剪贴板。你不需要访问权限,只需

认为你这样做。

问题是,我只能访问文本和URL格式。


你只能在IE浏览器中访问。

我想要一个HTML格式。这样做的原因是
我想在粘贴
内容之前在剪贴板中进行一些文本替换。
1)是否可以获取HTML格式的剪贴板数据?


No.

2)如果不可能,是否可以使用其他方法(或事件)
我可能不知道在粘贴之前更改内容?
Hi all,
On our site we have a section that allows users to copy and paste or
drag and drop the contents of (pretty much any) webpage into a Div.
I need to get access to the clipboard data. To do this I''m using the
..getData() function.
Only IE allows access to the clipboard. You don''t need access, you just
think you do.
Problem is, I only have access to ''Text'' and ''URL'' formats.
And you only have that access in IE.
I''d like to have an HTML format. The reason for this is that
I''d like to do some text replacements in the clipboard before the
contents are pasted.
1) Is it possible to get the clipboard data in HTML format?
No.
2) If not possible, is it possible to use some other method (or event)
I may be unaware of to alter the contents before they are pasted?




OnBeforePaste也许?最好使用onchange然后更改它。更多

可靠。


-

兰迪

comp.lang.javascript常见问题 - < a rel =nofollowhref =http://jibbering.com/faqtarget =_ blank> http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



OnBeforePaste maybe? Better to use the onchange and then change it. More
reliable.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


我应该指定。该网站运行在一个内部网和目标

浏览器ID IE - 唯一 - 。


我不认为我可以使用OnBeforePaste自唯一的方法我知道

在这个阶段检索内容是getData()。由于这个函数

不能给我HTML,我不能用它。如果错了,请纠正我。


onChange也不能使用,这就是原因:即使用户是

粘贴到DIV标签(启用了contenteditable,因此他们可以看到HTML格式的文本),数据被移动到一个隐藏的文本框中,所以

一旦提交,它的值就可以了可以通过服务器上的VB代码看到

方。当粘贴包含< FORM标签的HTML时,在提交时,

内容似乎是空白的(尽管javascript可以看到它们,

代码隐藏不可能。我正在使用VB .Net)

事实上,我正在尝试替换的是< FORM to"< xFORM"。

这个替换似乎允许代码隐藏看到值。

现在这里是奇怪的部分:如果替换发生在

粘贴之前,一切都很有用。如果我替换后粘贴

(使用onChange,如你所知)我得到一个空白值。

所以我的问题是:如何在粘贴之前获取内容事件,

所以我可以做替换?我的解决方案是使用getData,但是,唉,

似乎我不能在这里得到HTML。还有更多的想法吗?

I should''ve specified. The site runs on an intranet and the target
browser id IE - only -.

I don''t think I can use OnBeforePaste since the only way I know of to
retrieve the contents at this stage is getData(). Since this function
can''t give me the HTML, I can''t use it. Please correct me if ''m wrong.

onChange cannot be used either and here''s why: Even though the user is
pasting into a DIV tag (with contenteditable enabled so they can see
the text HTML formatted), the data is moved into a hidden textbox so
that upon submit, it''s value can be seen by the VB code on the server
side. When pasting HTML that contains a <FORM tag, upon submittal, the
contents appear to be blank (although javascript can see them, the
codebehind can''t. I''m using VB .Net)
In fact exactly what I''m trying to substitue is "<FORM" to "<xFORM".
This substitution seems to allow the codebehind to see the value.
Now here''s the weird part: If the substitution takes place BEFORE the
paste, everything works hunky-dorey. If I substitute AFTER the paste
(using onChange as u suggest) I get a blank value.
So my question is: How do I get to the contents before the paste event,
so I can do the substitution? My solution was to use getData, but alas,
it seems I can''t get at the HTML here. Any more ideas?


nAmYzArC在2005年12月19日下午5:40发表以下内容:


请引用您要回复的内容。


如果您想通过groups.google.com发布后续内容,请不要使用

"回复"链接在文章的底部。点击显示选项在

文章的顶部,然后点击回复。在

文章标题的底部。
nAmYzArC said the following on 12/19/2005 5:40 PM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don''t use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
我应该指定。该网站在内联网上运行,目标
浏览器仅限IE浏览器。
我不认为我可以使用OnBeforePaste,因为我知道的唯一方法是检索内容这个阶段是getData()。由于这个功能
不能给我HTML,我不能用它。如果错了,请纠正我。


使用getData()检索它时,您将获得纯文本。

剪贴板只知道纯文本。只有在你粘贴它后,浏览器会读取它才能识别HTML代码。提醒您剪贴板中的
内容,您应该看到代码本身。

onChange也不能使用,这就是原因:即使用户是
粘贴到DIV标签(启用了contenteditable以便他们可以看到HTML格式的文本),数据被移动到隐藏的文本框中,以便在提交时,它的价值可以通过服务器上的VB代码
I should''ve specified. The site runs on an intranet and the target
browser id IE - only -.
I don''t think I can use OnBeforePaste since the only way I know of to
retrieve the contents at this stage is getData(). Since this function
can''t give me the HTML, I can''t use it. Please correct me if ''m wrong.
When you retrieve it using getData(), you are getting plain text. The
clipboard knows of nothing but plain text. It is only after you paste it
and the browser reads it that it recognizes the HTML codes. alert the
contents of your clipboard and you should see the codes themselves.
onChange cannot be used either and here''s why: Even though the user is
pasting into a DIV tag (with contenteditable enabled so they can see
the text HTML formatted), the data is moved into a hidden textbox so
that upon submit, it''s value can be seen by the VB code on the server
side.




onbeforepaste =" getClipBoardData();"


其中getClipBoardData是读取剪贴板的函数。那么,它是
在一个变量中,你替换了< < x,一切都很好。


clipBoardData = clipBoardData.replace(/< /,''< x'')


那将取代所有<与< x


clipBoardData = clipBoardData.replace(''< form'',''< xform'')

formElementReference.value = clipBoardData;


将隐藏字段更改为正常输入以查看并测试它。


-

Randy

comp.lang.javascript常见问题 - http://jibbering.com / faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



onbeforepaste="getClipBoardData();"

Where getClipBoardData is the function to read the clipboard. Then, it
is in a variable, you replace the < with <x and all is well.

clipBoardData = clipBoardData.replace(/</,''<x'')

That will replace all < with <x

clipBoardData = clipBoardData.replace(''<form'',''<xform'')
formElementReference.value = clipBoardData;

Change your hidden field to a normal input to see it and test it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


这篇关于getData HTML格式???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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