如何控制或编辑从网页复制的文本(出于善意而非邪恶原因)
我的网络应用程序允许大学成员查找并显示他们的大学 ID 号。它以商定的格式 99999-9999 显示该号码,选择该格式是为了帮助将其与社会安全号码等区别开来,并使其更具可读性和更容易记忆。不幸的是,有一些下游应用程序,无论出于何种原因,都无法处理破折号并期望 9 位整数。当用户相当合理地使用剪切和粘贴从我的应用程序中捕获他们的 ID 号并将其插入上述脑死亡应用程序时,这就会成为一个问题。我无法修复,也无法施加压力来修复这些脑死亡的应用程序,而我却被迫删除连字符。但在我这样做之前,是否有一些简单、可靠的技术可以以某种方式让用户看到带连字符的 ID 号码,但导致不带连字符的号码被捕获 em> 使用浏览器复制/剪切操作?
My web application allows members of the university to lookup and display their university ID number. 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. Unfortunately there are a few downstream applications that, for whatever reason, do not cope with the dash and expect a 9 digit integer. 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. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然可以,现在您想从 Web 浏览器控件还是从外部 Internet Explorer 窗口复制它?如果是外部 IE 窗口,那么您将需要获取对此窗口的引用,这可以使用窗口标题完成,然后使用该引用(或者,如果在 Web 浏览器控件中,则直接使用 Web 浏览器控件),您可以通过标签/元素名称、标签/元素 id 或其他方式搜索该 id 所在的元素(即:您需要确定它是否在 div 标签或 span 标签等中)...一旦您找到它,获取对它的引用,可能使用 IHTMLElement声明您的引用类型...您将能够复制它并对其进行一些字符串操作并将其存储在您想要的任何位置,或者您可以使用新值更新页面上的实时值(实时编辑用户正在看到的页面,通过复制 id 来更改元素值,从字符串变量中的副本中删除连字符,然后将其分配回我们从中获取它的元素)。
您可以使用 elements .value 属性来读取元素并将其分配给元素,具体取决于元素,但大多数元素再次使用 .value 或 insidetext,具体取决于标签/元素:)。
如果您需要一些代码,请告诉我,您需要告诉我们正在处理的元素,或者您想要使用的学生 ID 周围内容的 HTML 示例。
Of course you can, now are you wanting to copy it from your web browser control or from an external internet explorer window? 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).
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 :).
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.