PDA

View Full Version : سوال: جلوگیری از انتخاب (Select) کردن متن



Keyhan Clever
پنج شنبه 11 تیر 1388, 20:33 عصر
دوستان چجوری میشه که از انتخاب (Select) شدن متن در تمام مرورگر ها جلوگیری کرد و نه فقط در Internet Explorer چون الآن خیلی ها از Firefox و NetScape استفاده میکنن

silverfox
پنج شنبه 11 تیر 1388, 20:50 عصر
<script type="text/javascript">

/***********************************************
* Disable Text Selection script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

function disableSelection(target){
if (typeof target.onselectstart!="undefined") //IE route
target.onselectstart=function(){return false}
else if (typeof target.style.MozUserSelect!="undefined") //Firefox route
target.style.MozUserSelect="none"
else //All other route (ie: Opera)
target.onmousedown=function(){return false}
target.style.cursor = "default"
}

//Sample usages
//disableSelection(document.body) //Disable text selection on entire body
//disableSelection(document.getElementById("mydiv")) //Disable text selection on element with id="mydiv"

</script>
غیر فعال کردن select در body:


<script type="text/javascript">
disableSelection(document.body) //disable text selection on entire body of page
</script>
در یک div با id=mydiv


<script type="text/javascript">
var somediv=document.getElementById("mydiv")
disableSelection(somediv) //disable text selection within DIV with id="mydiv"
</script>
تمام tableها:


<script type="text/javascript">
var alltables=document.getElementsByTagName("table")
for (var i=0; i<alltables.length; i++)
disableSelection(alltables[i]) //disable text selection within all tables on the page
</script>
منبع هم dynamicdrive.com هست یه سر بزن در این زمینه ها خیلی کمکت می کنه مثال های خوبی داره و مزیتش هم اینه که کاملا توضیح داده یعنی حتی کسی که html هم بلد نیست می تونه ازش استفاده کنه کاملا همه چی رو توضیح داده...
یه نظر شخصی هم دارم اینه که کسی که بخواد مطالب رو برداره خوب صفحه رو save می کنه بعد کپی می کنه اگه مطالب رو نمی خوای بردارن اصلا چرا می ذاری توی سایت یا وبلاگ و یه جورایی کلاس وبلاگ یا وبسایت رو پایین میاره(نظر شخصی)