How can one detect copying a link in a browser?

后端 未结 4 2275
自闭症患者
自闭症患者 2021-02-14 04:53

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 c

相关标签:
4条回答
  • 2021-02-14 05:24

    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.

    0 讨论(0)
  • 2021-02-14 05:27

    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.

    0 讨论(0)
  • 2021-02-14 05:28

    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 讨论(0)
  • 2021-02-14 05:46

    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.

    0 讨论(0)
提交回复
热议问题