1

I want to lock the copy button but don't want to lock save as button which is totally right click ,so a user of my site can save the website as a html file but can not copy text ,How can I do it with Javascript guys?

vishalkin
  • 996
  • 2
  • 11
  • 23
  • 1
    hmm.. i didn't understand why do you want such functionality? isn't it making your site less favorable? – bansi Oct 06 '13 at 14:36

3 Answers3

2

You can use this CSS:

user-select: none;

This makes the text on the site not selectable, so the user would not be able to highlight and copy any of it.

Additional information can also be found on this site here:

How to disable text selection highlighting using CSS?

Community
  • 1
  • 1
Charlie74
  • 2,791
  • 12
  • 22
  • But the user can invoke the context menu and then copy text. – Arun Aravind Oct 06 '13 at 14:35
  • @ArunAravind that is incorrect. If the text cannot be highlighted, you cannot right-click and copy it. You must be able to highlight the text first. – Charlie74 Oct 06 '13 at 14:36
  • sorry for the downvote. That was a mistake. He said he wanted to have the save as menu. And user-select is not supported in older browsers. – Arun Aravind Oct 06 '13 at 14:38
  • 1
    In any case they would always have the option to "view source" and copy it that way. Not sure I see any point in this requirement. – Paulie_D Oct 06 '13 at 14:40
0

use

document.body.oncontextmenu = function(evt) { 
       // do custom menu stuff;
       evt.preventDefault();
}

this will disable the context menu as such.

This is supported in almost all browsers. Then you may create a custom menu with "Save As" option. You could do this with pure css.

Arun Aravind
  • 988
  • 6
  • 8
0

This is the perfect code if you dont want the users to select your text without diableing the right click

body
{
    -webkit-user-select: none;
        -moz-user-select:none;
        -o-user-select:none;
}
saim imtiaz
  • 66
  • 1
  • 6