标签云

微信群

扫码加入我们

WeChat QR Code

制作文字无法选取[复制]

This question already has an answer here:

So, while playing with scrollbars and stuff in HTML5, I'm starting to notice an annoying trend. If I have text near my element that's being dragged (say, a scrub bar for a video, scroll bar, anything a user would click and drag), nearby text will get selected, as if I'm not using a control, just dragging over the page.

This is terribly annoying, and I can't seem to find the right string to search for on google to figure out if it's possible to make certain elements "unselectable".

Anyone know how to do this?


Awesome! I'm embarrassed that I've made it this far without knowing that.

2018年05月27日33分29秒

Just know that the -moz one only makes the appearance of selection invisible, it doesn't disable it functionally. developer.mozilla.org/en/CSS/-moz-user-select

2018年05月28日33分29秒

There's also -o-user-select for Opera and the unselectable expando property for IE. See my answer for full details.

2018年05月27日33分29秒

Marcel If it wasn't before, it is now (as I'd expect...). Just saying.

2018年05月27日33分29秒

I just tried it out in a few browsers I have installed for Windows (Fx 3.6 and 13, Chrome 20b, Opera and IE10). Firefox 3.6 seemed to work the best between highlighting the specific element, highlighting sibling elements and content copied to the clipoard with this method. The latest stable Opera still doesn't support blocking any of this and I couldn't get anything to work in IE10, even setting the unselectable="on" attribute.

2018年05月28日33分29秒

You're right when IE9 is in standards mode (in compatibility modes the unselectable property works fine). I've now updated five of my answers involving unselectable (apparently that's the maximum number of edits allowed to your own posts in a day. I've no idea why). Odd that one of your edits was approved and an identical one rejected.

2018年05月27日33分29秒

Some background as to why this change has happened in IE 9: msdn.microsoft.com/en-us/library/ie/gg622931%28v=vs.85%29.aspx

2018年05月27日33分29秒