• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

How to disable copy&paste in a webpage for different browsers

anyone know how to disable copy&paste function that works on some browsers such as IE,firefox,opera,safari,etc?
i've tried this code : <body onselectstart="return false;" onmousedown="return false;">
this code can works properly on those browsers,it prevents me to select and copy the text.But, on firefox,opera,and safari, all the textboxes are disabled also,i can't input any value in it.Only on IE allow me to input a value.
Is there other script that can fix this problem? thanks
0
chinsw
Asked:
chinsw
1 Solution
 
Gurvinder Pal SinghCommented:
try this
ondragstart="return false" ;
onselectstart="return false";
0
 
Gurvinder Pal SinghCommented:
you can also try


document.onmouseup = function(e) 
{
	if(window.getSelection){
		t = window.getSelection();
	  }else if(document.getSelection){
		t = document.getSelection();
	  }else if(document.selection){
		t = document.selection.createRange().text;
	  }		
	  if (t.length > 0) 
	  {
		t = 0;
		return false;
	  }
}

Open in new window

0
 
chinswAuthor Commented:
@gurvinder372
thanks for ur reply,but the first code is only applicable for IE,others still can copy. and the second code is also not working at all.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Gurvinder Pal SinghCommented:
can you try the following also
http://www.articlesbase.com/programming-articles/how-to-restrict-copy-and-paste-using-javascript-1003078.html
http://www.arraystudio.com/as-workshop/disable-ctrl-n-and-other-ctrl-key-combinations-in-javascript.html

you can check at the press of control key
onKeyDown="return noCTRL(event)"

function noCTRL(e)
{
var code = (document.all) ? event.keyCode:e.which;

var msg = "Sorry, this functionality is disabled.";
if (parseInt(code)==17) //CTRL
{
alert(msg);
window.event.returnValue = false;
}
}

0
 
chinswAuthor Commented:
ok,the code is used to prevent users to copy the text using CTRL key and right click.But,i still can copy the text if i select and block the text than got to Edit --> Copy. any script to prevent users to select and block the text also? i try this onselectstart="return false"; only applicable for IE.
0
 
Gurvinder Pal SinghCommented:
can you try
document.onmousedown = false;
document.onmouseup = false;
or simply
document.oncontextmenu = false;

also
function disableselect(e)
{
return false
}
function reEnable()
{
return true
}
//document.onmouseup=new Function ("return false");

document.onmousedown=disableselect
document.onclick=reEnable

0
 
manjunathubCommented:
This may help you it will work in IE and FireFox, not tested in other browsers...
<html>
	<body  oncopy="return false" onpaste="return false" oncut = "return false">
	body
	
	<input type ="text" oncopy="return false" onpaste="return false" oncut = "return false"/>
	input 1
	<input type ="text" oncopy="return false" />
	input 2
	<input type ="text" onpaste="return false"/>
	input 3
	</body>
</html>

Open in new window

0
 
sybeCommented:
There are always ways to get around this disabling of copy/paste. What remains is an annoying feature of a web page. For example while reading a web page, I often highlight the lines I am currently reading. Why would you not want me to do that?
0
 
chinswAuthor Commented:
thanks for all of ur replies...now i'm using jQuery method to do...and i combine with gurvinder372's code above. thank you.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now