user34537
user34537

Reputation:

Stop text selection from going outside a div?

I am pretty sure i seen sites that make firefox (and other browsers?) select text only within a div and not span across other divs. How do i do that

Upvotes: 4

Views: 3098

Answers (2)

dav
dav

Reputation: 9267

it seems giving overflow: hidden encloses the text selection in that div only.

Hope it helps

source https://stackoverflow.com/a/5505944/932473

Upvotes: 2

Hamid Nazari
Hamid Nazari

Reputation: 3983

Based on this.

<html>
    <head>
        <title>No Select!</title>
        <script>
            window.onload = function() {
                document.onselectstart = function() {return false;} // ie
                document.onmousedown = function() {return false;} // mozilla
            }
        </script>
    </head>
    <body>
        Select me!
    </body>
</html>

By the way try to avoid this kind of stuff as it's not cool to prevent visitors from their basic rights!! If someone wants to select a text, they'll know how to do it and there's no way to prevent it.

Upvotes: 0

Related Questions