-2

i have two download links. after right click on this link it showing option link "open in new tab" "save link as" "copy link location" and so on. but i want to protect this link. there should not showing this option when right click on download link. please help

Thanks in advance

Neeya
  • 135
  • 8
  • 3
    If you don't want people to download something, then don't put it on the internet. For anyone to even *see* it, it must be *downloaded* to their computer. Saving it into a separate file from there is trivial and there's no protection against it. – deceze Mar 30 '17 at 07:49
  • i dont want to this protection. this process is working fine in my code which you have mentioned above. my requirement is only that when user right click on link this option "open in new tab" "save link as" "copy link location" and so on cant not be showing to user – Neeya Mar 30 '17 at 07:54
  • or user cant able to right click on lick. he will only able to download link when left click on link – Neeya Mar 30 '17 at 07:56
  • You cant block a file being downloaded with right click even cancelling click event, there is always options to open the context menu :S The best approach is protect it server-side, and if you want to do it anyway client side, your best option is to create your custom html context menu on click event, but is not a solution to the problem :S – Diego N. Mar 30 '17 at 08:01
  • *Why* don't you want people to open the link in a new tab or "save as"? What exactly is your concern? – deceze Mar 30 '17 at 08:06
  • i dont want to show download link to user – Neeya Mar 30 '17 at 08:20

2 Answers2

0

You can't protect anything with client languages like javascript or html/css. If the browser can, an human can

You can create an unique download link in PHP, or create a password (unique too) to allow the user to get his file with expiration date for example.

Else, you can send the file in an e-mail as attachment.

They are many ways to do what you want, but only with a serverside language.

Thomas Rbt
  • 1,483
  • 1
  • 13
  • 26
0

Use context menu event to prevent the menu from showing:

document.getElementById('downloadThisPage').addEventListener('contextmenu', function (event) {
    event.preventDefault();

    return false;
});
Matansh
  • 764
  • 4
  • 13