سؤال

Hi I found this webpage today: http://www.snopes.com/inboxer/hoaxes/sister.asp

I couldn't figure out how it disable text selection. It's neither the conventional CSS or javascript method. Do anyone know how it disable the text selection?

هل كانت مفيدة؟

المحلول

Look in the Javascript source:

<!--
var omitformtags=["input", "textarea", "select"]
omitformtags=omitformtags.join("|")
function disableselect(e){
  if (omitformtags.indexOf(e.target.tagName.toLowerCase())==-1)
    return false
}

function reEnable(){
  return true
}

if (typeof document.onselectstart!="undefined")
  document.onselectstart=new Function ("return false")
else{
  document.onmousedown=disableselect
  document.onmouseup=reEnable
}
-->

When the user attempts to start a selection, onselectstart, it simply returns false, which disables the feature.

نصائح أخرى

Try this simple Javascript method.

document.onselectstart = function() { return false; }
document.onmousedown = function() { return false; }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top