【问题标题】:Prevent text selection when dragging from outside target in IE7/8在 IE7/8 中从外部目标拖动时防止文本选择
【发布时间】:2012-03-30 07:49:51
【问题描述】:
【问题讨论】:
标签:
html
css
internet-explorer
internet-explorer-8
internet-explorer-7
【解决方案1】:
IE8-onselectstart event 和unselectable attribute 解决方案已经讨论过了。
CSS solution 也已发布。这是要点:
<!-- save this file as unselectable.htc and remember where you put it -->
<public:component lightweight="true">
<public:attach event="ondocumentready" onevent="unselectable()" />
<script type="text/javascript">
function unselectable(){
element.onselectstart = function(){ return false; };
element.setAttribute('unselectable', 'on', 0);
}
</script>
</public:component>
/* add this rule to the existing CSS file */
.unselectable {
user-select: none;
-moz-user-select: none;
-khtml-user-select: none;
behavior: url(unselectable.htc); /* change this path as needed */
}