How can one detect copying a link in a browser?

后端 未结 4 2274
自闭症患者
自闭症患者 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.

提交回复
热议问题