开发者

text selection in ipad html

开发者 https://www.devze.com 2023-01-09 14:09 出处:网络
开发者_Python百科I have a div with text inside of it. I want the text to be selectable (for copy/paste) on the iPad. At the same time I want to be able to handle an onclick event.

开发者_Python百科I have a div with text inside of it. I want the text to be selectable (for copy/paste) on the iPad. At the same time I want to be able to handle an onclick event. This seems not to go well together. As soon the div is clickable it is not selectable.

Does anybody know a way around this?

<html>
 <head>
  <script>

function run() {

    // do some stuff here...
}


 </script>
</head>
<body>
  <!-- removing this onclick makes the div selectable -->
  <div onclick="run()">
  <p>AAA aaaa aaaa aaaa<p>
  <p>bbbbb bbbb BBBBB</p>   
  <div>
</body>


You should use event handlers for iOS web interaction:

// Replace "document" with the element you want it to apply
// to through getElementById("anId")

document.addEventListener("touchstart", run, false);

This will call run() when a touch has started.

The default methods of onclick, onmousedown, etc. behave weirdly on iPhone, iPod touch, and iPad.

More here

0

精彩评论

暂无评论...
验证码 换一张
取 消