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

116 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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.