开发者

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 addre开发者_如何学Goss 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.


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.


This used to be possible with IE7 and older versions of Flash 10.

In IE7 (and 8 I think), you can simply:

var vulnerability = window.clipboardData.getData("Text");

This is a vulnerability, and in IE9 is disallowed by default. In Firefox hooking into the Clipboard interface is also disallowed by default. In Safari/Chrome this not allowed either, EXCEPT explicitly in onPaste handlers.

In Flash, you could simply do Clipboard.getData() prior to several months ago. The Clipboard now has write-only access in Flash (but still retains it's full capability in Air).

In IE, you can see how trivial this would be to do. Simply call window.clipboardData.getData("Text") every couple of seconds. With Flash, it wouldn't have been much harder. Simply hook a Javascript function into your Flash video and loop the video.

Accessing the clipboard in the aforementioned type of ad hoc manner is presently impossible on all major browsers.


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.


I've seen a couple of sites that disable right click events anywhere on the page, with a message similar to your

Please don't copy this link, rather register

I guess that is done using javascript. Maybe with IE you can have ActiveX control that gives the developer more control over the browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜