chinsw
asked on
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,et c?
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
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
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;
}
}
ASKER
@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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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=disab leselect
document.onclick=reEnable
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=disab
document.onclick=reEnable
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>
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?
ASKER
thanks for all of ur replies...now i'm using jQuery method to do...and i combine with gurvinder372's code above. thank you.
ondragstart="return false" ;
onselectstart="return false";