简体   繁体   English

如何控制或编辑从网页复制的文本(出于良好而非邪恶的原因)

[英]How to control or edit text that is copied from a web page (for good, not evil reasons)

My web application allows members of the university to lookup and display their university ID number. 我的Web应用程序允许大学成员查找并显示其大学ID号。 It displays that number in an agreed upon format 99999-9999 which was picked to help distinguish it from, say, a Social Security Number, and to make it a bit more readable and easier to memorize. 它以商定的格式99999-9999显示该号码,以帮助将其与社会安全号码区分开来,并使其更具可读性和易记性。 Unfortunately there are a few downstream applications that, for whatever reason, do not cope with the dash and expect a 9 digit integer. 不幸的是,出于某些原因,有一些下游应用程序无法应付破折号,并期望使用9位整数。 This becomes a problem when users, quite reasonably, use cut and paste to capture their ID number from my app and plug it into the afore mentioned brain dead app. 当用户非常合理地使用剪切和粘贴从我的应用程序中捕获其ID号并将其插入上述提到的大脑死机应用程序时,这将成为一个问题。 I am unable to fix, nor can I apply pressure to have fixed, the brain dead apps, while I am being pressured to remove the hyphen. 当我被迫删除连字符 ,我无法修复,也无法施加压力修复那些脑瘫的应用程序。 But before I do that, is there some straightforward, reliable technique that would somehow allow the user to see the ID number with the hyphen, but cause the number without the hyphen to be captured with a browser copy/cut operation? 但是在我这样做之前,是否有一些简单,可靠的技术可以某种程度上允许用户看到带有连字符的ID号,但是却导致没有连字符的数字被浏览器的复制/剪切操作捕获了?

Of course you can, now are you wanting to copy it from your web browser control or from an external internet explorer window? 当然可以,现在您是要从Web浏览器控件还是从外部Internet Explorer窗口复制它? If external IE window, then you will need to get a reference to this window, which can be done using the windows title, then using that reference (or, if in a web browser control, directly using your web browser control), you can search for the element where that id resides in either by tag / element name, or tag / element id, or other means (ie: you will need to figure out if its in a div tag or span tag etc)... Once you find it, get a reference to it, probably using IHTMLElement to declare your reference type... And you'll be able to either copy it and do some string manipulation on it and store it wherever you want, or you can just update the live value on the page with the new value (live editing on the page the user is seeing, to change the elements value by copying id, removing hyphen from copy in a string variable, and then assigning it back to the element we got it from). 如果是外部IE窗口,则需要获取对该窗口的引用,可以使用Windows标题,然后使用该引用来完成(或者,如果在Web浏览器控件中,则直接使用Web浏览器控件),您可以通过标签/元素名称,标签/元素ID或其他方式搜索该ID所在的元素(例如:您将需要确定其是否在div标签或span标签中)等。找到它,获得对它的引用,可能使用IHTMLElement声明您的引用类型...,您将能够对其进行复制并对其进行一些字符串操作,然后将其存储在所需的位置,也可以只更新具有新值的页面上的实时值(用户正在查看的页面上的实时编辑,通过复制id来更改元素值,从字符串变量中的副本中删除连字符,然后将其分配回我们从中得到的元素)。

You can use the elements .value property to read from and assign to the element, depending on the element, but most elements use .value or innertext, once again, depending on the tag/element :). 您可以根据元素使用元素.value属性读取和分配元素,但大多数元素还是根据标签/元素:)再次使用.value或innertext。

Let me know if u need some code you will need to tell us what element we are dealing with, or the HTML sample of what surrounds the student Id you want to play with. 让我知道您是否需要一些代码,您将需要告诉我们我们正在处理什么元素,或者是您想要玩耍的学生ID周围的HTML示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM