Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one detect copying a link in a browser?

Yesterday I had a chat with a taxi driver and upon mentioning that I am a programmer, he told me that a couple of days earlier he had experienced the following: upon trying to copy the URL from the address bar of his browser, a messagebox appeared with a message like "Please don't copy this link, rather register".

I am not a web developer, so this might be a lame question :-) but I wonder how such a thing is accomplished? What technology or language gives one this level of control over the events within the browser?

The site was some sort of a movie downloading service, as far as I understood. I failed to ask him what browser he used, but his platform was WinXP so most probably it was IE. Since I have no idea of the technology implementing this feature, I can't add any technology specific tags, but if you know an appropriate one, feel free to add it.

Disclaimer :-)

Upon reading the answers, most seem to converge on the opinion that

  • on the browser page it is fairly easy to achieve, but
  • on the address bar it is not, if possible at all.

I specifically asked back to make sure that he meant he was copying the URL from the address bar, and he confirmed that. Nevertheless, it might still be a misunderstanding on either side. I haven't seen the event happening, so I can only repeat its description as I heard it.

like image 446
Péter Török Avatar asked Dec 04 '10 22:12

Péter Török


People also ask

Can websites detect copy?

There are a few ways a website can track whether someone is copying and pasting text. One way is to use a plugin that tracks this activity. This plugin can track attempts to copy text and images from the website, or disable the corresponding functions altogether.

What happens if you copy a link?

In the right-click menu that appears choose the right-click, Copy link address, or Copy link location option (varies by browser). Once done that address is copied into your clipboard and can be pasted into e-mail, document, spreadsheet, notepad, or any other file or web page.


2 Answers

For one, there is the rightclick event. This is easy to catch and react on.

There also is the more general contextmenu event, but it does not apply to browsers other than IE.

I guess that they simply prevented the right click on links, based on the assumption that no-one right-clicks on a link for any other reason than copying it. So he did not even get as far as selecting "copy link" from the context menu, the message just appeared immediately.

There are keyboard-based methods of opening the context menu, and I expect they still would have worked.

The simplest jQuery implementation of this behavior is a three-liner:

$("a").rightclick(function () {
  alert("Please don't copy our links!"); return false;
});

As for "preventing copy from the address bar" - no way. They could not possibly have done this.

like image 83
Tomalak Avatar answered Sep 21 '22 08:09

Tomalak


Address bar - no, not possible, if a browser allowed a page to intercept the addressbar then it would raise a lot of security issues.

It was most likely the page either preventing a right click on a link, or doing CTRL+C within the page itself.

If it was IE, then there's the possibility that they unwittingly installed an ActiveX control when visiting the site, which may have prevented them from copying a link from the address bar.

like image 45
Ben Avatar answered Sep 24 '22 08:09

Ben