2014年2月26日 星期三

javascript 鎖右鍵、鎖選取文字

as title
var omitformtags=["input", "textarea", "select"];
function disableselect(e){
 for(i = 0; i < omitformtags.length; i++){
  if(omitformtags[i]==(e.target.tagName.toLowerCase()))return;
 }
 return false
}
function reEnable(){return true}
document.write('<div style="position:absolute;visibility:visible;top:-3000px;left:-3000px;"><form name="_hiddenFrom"><input type="text" value="喔喔!你按Ctrl-A喔!" name="_hiddenText"></form></div>');
if(typeof document.onselectstart=="undefined"){
 document.onmousedown=disableselect;
 document.onmouseup=reEnable;
}else{
 document.onmousedown=new Function("return false");
 document.onmouseup=new Function("return false");
}
document.onselectstart=new Function("return false");
document.onselect=new Function("return false");
document.oncontextmenu=new Function("return false");
onload=document._hiddenFrom._hiddenText.focus();

沒有留言:

張貼留言