Unselectable text - Cross browser solution

2019-05-21 13:44发布

问题:

Is there any equivalent for -moz-user-select / -webkit-user-select for IE6 ?

I would like the text on my page not to be selectable in all major browsers.

What is the best solution for that ?

回答1:

Here's the example

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Unselectable text</title>
</head>

<body style="height: 100%; padding: 0; margin: 0;">

<style>
  .column {width: 30em; margin: 1em;}
  p {position: relative; z-index: 1; //height: 100%;} /* you can remove //height if declare doctype */ 
  .unselector {display: block; position: absolute; z-index: 2; width: 100%; height: 100%; top: 0; left: 0;}
  .unselector img {display: block; position: absolute; z-index: 3; width: 100%; height: 100%;}
</style>

  <div class="column">
    <p>
    <span class="unselector"><img src="1.gif" alt="" border="0" /></span>
    Activists on&nbsp;ships raided by&nbsp;Israeli commandos cast doubt on&nbsp;Israel's version of&nbsp;events that led&nbsp;to at&nbsp;least nine deaths. Yes, the webpage is currently not available. 
    </p>
  </div>

</body>
</html>

p.s. 1.gif is transparent 1px*1px image



回答2:

if this is for a small element masking, i will go with have an empty DIV over the text, and giving the DIV an absolute position with z-index higher than the text's. make sure the DIV is coving everything.