132

There's a website (example) that somehow blocks selecting text. Also it blocks Ctrl+A to select everything, there is also no “Copy” in the popup menu.

What I have tried:

Some sites use JavaScript to block selection. So I disabled all JavaScript sources in no-script addon in Firefox. I tried the same site in Google Chrome with the Script Safe addon. Made sure that everything is blocked, still can’t select text. Mousepointer remains an arrow and not a text cursor also on the whole site.

Used about:config to disable JavaScript completely in Firefox. Still no effect.

I read that some sites use DIVs with the style display:block so I used Inspect to examine the styles of the site. There is not one mention of "block" on the whole website, not in embedded CSS nor in object style=-attributes.

The text is not an image or flash or some HTML5 canvas ect. Everything is within DIV and P tags but no style was found that might block the text selection.

How can the website still block any selection of text? Not to mention why browsers support such behaviours at all. I just want to use a selected word or sentence and want to search google for it using right mouse click. It’s pretty annoying when a website does such things and forces me to type technical terms and names into google by hand. It disturbs my workflow.

14
  • 13
    "How do websites block marking of text" - They set style.userSelect to none.
    – user766703
    Commented Jan 5, 2018 at 9:52
  • 7
    @Xen2050 Mostly I don't care about copying text. I just love the ability to mark phrases and terms and search for it on Google with just a click of the mouse (doubleclick word, rightclick "Search Google..."). I could go into the source (if it's clean source at all) and scan for the word, copy it, paste in Google but well... as said this is just an annoyance. Some1 who wants to copy your website text can do it anyhow but someone who just wants a comfortable workflow gets hindered. Commented Jan 5, 2018 at 13:47
  • 153
    Can we just take a moment and sympathize for all the delusional web developers out there who think this is a good security measure?
    – MCMastery
    Commented Jan 5, 2018 at 15:17
  • 43
    @MCMastery Or worse, the developers who know it's terrible but are told they have to do it anyway. Most of the time they are worried about people stealing content. Then you've got sites like SO who are getting scraped/stolen from all the time... but commercially viable. Turns out alienating your userbase is bad for business. Who would have thought?!
    – corsiKa
    Commented Jan 5, 2018 at 20:39
  • 4
    @MCMastery - the goal, as usual, is not to be faster than the dinosaur. The goal is to be faster than the dude next to you. Just as a goal of a lock isn't to defeat a burglar, it's to introduce more friction for them to go burgle someone else. Or in other words, the goal of the measure is not to introduce bulletproof security; it's to introduce enough friction to (a) deter casual copier and (b) make a less casual copier more interested in less-work-required-to-copy alternative sites.
    – DVK
    Commented Jan 7, 2018 at 21:12

17 Answers 17

104

https://www.angst-panik-hilfe.de/angst-panik.css shows:

body{-webkit-user-select:none;-moz-user-select:-moz-none;
-ms-user-select:none;user-select:none}

So, that effect applies to the entire BODY tag.

Documentation on this CSS: Mozilla Developer Site: user-select.

You could probably override this by removing the style in Developer Tools (press F12 in Firefox or Chrome) - you may even be able to create a JavaScript applet that, after investing the time to set this up, can remove that style with less instant effort on your part (which may be a time saver if you plan to visit the site multiple times).

I'd also like to add this note: This might not be the only way to have at least some of that effect. Another possible way could be to have an invisible DIV cover the DIV that has the text. That way, the mouse cursor would not turn into the I-beam (text cursor) because the cursor would be based on the content of the top-most DIV. (Ctrl-A would probably cover that text, though.)

It's pretty annoying when a website does such things and forces me to type technical terms and names into google by hand. It disturbs my workflow.

Amen! Upon seeing this, I'm disappointed at the existence of such a CSS style being implemented by the major browsers. Such things are pretty annoying, indeed!

19
  • 68
    The user-select CSS style is pretty helpful when applied responsibly. For instance, if you want (especially older) users on a touchscreen clicking on buttons near label text, you don't want them to mark the label text instead of clicking the button.
    – phihag
    Commented Jan 5, 2018 at 14:00
  • 14
    What do you mean "by default"? This setting is only enabled if the website specifically enables it, that doesn't sound like "by default" to me. There will always be features that can be misused by bad web designers, there's not much you can do to prevent that without negatively affecting those who do have a legitimate reason to use those features... Commented Jan 5, 2018 at 15:18
  • 14
    @SeanT Again, if the browser exists to serve the person looking at webpages, then its job is to respond to what the web server sends however the user tells it to. If the user tells it to mute the page, or disallow pop-ups, or copy text, then the browser should do so. Commented Jan 5, 2018 at 16:14
  • 8
    No browser user is going to go to the bother of configuring their browser to explicitly enable a feature like this one, if it's not enabled by default then it's essentially useless and might as well not be implemented at all. And if you are suggesting that every feature must be explicitly enabled by the user, then where do you draw the line? Must the user enable the "images" feature before a website can display images? Must all browsers basically be Lynx by default until the user enables all the features they want? Commented Jan 5, 2018 at 16:16
  • 14
    @Acccumulation The user-select: none feature is used all over the place to maintain the style of a webpage e.g, stopping an ugly blue background when selecting an option from drop down lists. You just don't notice because it's being implemented correctly. The problem here is that it's been implemented in a restrictive way to the user, and a browser has no way to differentiate between the two. Therefore, blame the dev's :)
    – Sean T
    Commented Jan 5, 2018 at 16:57
39

As has already been stated, setting user-select: none in the page's CSS is what disables selection of text on a page. The easiest way to remove that text selection block would be through a user script like the following that overrides the setting:

// ==UserScript==
// @name         Force Select
// @version      1.0
// @description  Stop sites from disabling selection of text
// @author       You
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  let style = document.createElement('style');
  style.innerHTML = '*{ user-select: auto !important; }';

  document.body.appendChild(style);
})();

Note: This will apply to every page if left enabled, which might not be desirable in all situations.

The script can be installed and easily toggled on/off with a user script manager such as Violentmonkey, Tampermonkey, or Greasemonkey.

4
  • 1
    This will apply to every page if left enabled, which might not be desirable in all situations. Could you not just nest the function in an if statement that executes the script only if the URL matches a particular site or array of sites? Commented Jan 9, 2018 at 3:33
  • 1
    @Hashim That isn't necessary; you can specify which pages it applies to with one or more @match statements, but that would require modifying the script when you wanted it to apply to a specific page, unless you only visit a specific site or set of sites that you always want to modify. For the example script I made it generic by using *://*/* as the URL to match, so it will apply everywhere. It can be toggled on and off from the menu of the user script manager.
    – Herohtar
    Commented Jan 9, 2018 at 3:55
  • In my case, the css rule that worked was body * :not(input):not(textarea) { user-select: auto !important; -webkit-user-select: auto !important; }
    – Keyslinger
    Commented Jan 27, 2022 at 4:35
  • This site brought me here hildastouchofspice.com/2011/12/marzipan.html#prettyPhoto . The above answer plus superuser.com/a/964711/617826 does the trick.
    – DannyBoi
    Commented Dec 17, 2022 at 4:02
18

The simplest way to solve this problem is by using a bookmarklet:

  1. In your browser create a new bookmark.
  2. Name it, for example, "Enable Selection" (without quotes), or however you like.
  3. In the location textbox paste this code:
javascript:(function(){var style=document.createElement('style');
style.innerHTML='*{user-select: auto !important;} ::selection{background-color: blue !important; color: white !important}';
document.body.appendChild(style);
document.body.onselectstart=function(){return true};
document.body.onmousedown=function(){return true};
document.onkeydown=function(){return true};
})();

So whenever you want to enable text selection on some annoying web site, just click on this bookmark.

This code takes care of most frequent CSS and JavaScript-based ways that a-holes use to disable text selection on their web sites. Although some less frequent ways might require some additional adjustments to the code.

7
  • Works great! This should be the new accepted answer
    – towe
    Commented Feb 4, 2022 at 8:28
  • I came across a webpage where appending a style element didn't work so I changed it to this: var body = document.getElementsByTagName("body")[0]; body.setAttribute("style", 'user-select: auto !important;-webkit-user-select: auto !important;');
    – t3chb0t
    Commented Jul 11, 2022 at 20:16
  • nice, need more one code with context after onselectstart, we need context for copy a text document.body.oncontextmenu=function(){return true};
    – KingRider
    Commented Dec 27, 2022 at 17:10
  • Best solution for the challenged and lazy @rses ^_^
    – Whoever
    Commented Jan 1, 2023 at 13:43
  • Works perfect. Thank for saving time and effort. Commented May 15, 2023 at 8:48
17

You can hit Ctrl + P and grab what you need from the print preview.

enter image description here

2
  • 3
    Neat trick, for those who don't want to install yet another extension or meddle with the developer tools console.
    – Simón
    Commented Nov 19, 2022 at 21:46
  • Great hack. Too bad it often radically changes the styling of the page, making it hard to find the text again.
    – Al Ro
    Commented Jan 10 at 21:08
16

Open the developer tools (F12), change to the Elements tab, and untick the following CSS rules under body:

  • user-select: none;
  • webkit-user-select: none;

Demo Image

12

With Firefox, there's a really easy way:

View > Page Style > No Style

In German:

Ansicht > Webseiten-Stil > Kein Stil

enter image description here

It also works great to download embedded images on which right-click has been disabled.

2
  • 1
    Yeap, it works also on IE11. Commented Feb 20, 2018 at 13:37
  • Firefox 91.11.0esr: FWIW, I can toggle View > Page Style > No Style back to Basic Page Style and gain text selection capability...FYI, you MAY have to interact with the No Style page a bit before toggling back...
    – Digger
    Commented Nov 22, 2022 at 19:04
6

I'm using Stylus (https://add0n.com/stylus.html) and I made a style to apply to all websites, and thus I am ensuring everything is selectable:

* {
  -webkit-user-select: auto !important;
  -moz-user-select: inherit  !important;
  -ms-user-select: inherit  !important;
  user-select: auto  !important;
}

The asterisk is to make sure the style is not only applied to a certain css element (like <body>), but to all elements. I encountered cases where the selection blocking was applied to a button text only, so making a css for <body> would not help.

I use selection for instant translation on foreign language websites.

2
  • I fixed the formatting and the visibility of the inline <body> tag; see superuser.com/help/formatting
    – Arjan
    Commented Jan 7, 2019 at 15:10
  • you are the best bro
    – nim
    Commented Aug 11, 2022 at 20:33
3

As other answers have stated, its to do with the CSS on the body of the pages. Whilst you can edit this by hand every time, if you use this site a lot, I would suggest that if you use Chrome, you install the Stylish extension.

Stylish lets you create additional CSS to apply to pages. It can be used all over the web. It has the benefit of automatically applying whenever you visit the website (so you don't need to add it via the dev tools on every page load).

Once installed, click on the icon in the toolbar and select "Create New Style". It will automatically create the entry for the website you are currently visiting. You can then add any CSS you like to the page. But be warned: some styles may not be overriddable (especially if its written on the element itself, rather than a CSS class).

In this case, you can use the import function, and add the below code, this should allow you to select the text on the website you linked to.

@-moz-document domain("www.angst-panik-hilfe.de") {
  body {
    -webkit-user-select: auto !important;
    -moz-user-select: inherit  !important;
    -ms-user-select: inherit  !important;
    user-select: auto  !important;
  }
}
2
  • Adding webkit and ms prefixes for something that will only run on firefox is a bit... redundant. Commented Jan 8, 2018 at 12:31
  • 1
    @StephanBijzitter True, I just overwrote all the styles relating to user-select already on the page. But then again, it does mean that someone not using chrome but with a similar extension could fairly easily copy this class and gain the same benefit without work - and it doesn't really harm the solution. Commented Jan 8, 2018 at 12:33
2

I prefer using "bookmarklets" to user scripts or browser extensions. Try using one of the many bookmarklets to disable CSS & grab the required text

As it is may mess up the readability of web-page, I sometimes open the page in a different tab (right click on tab, select Duplicate) before removing the styling with the bookmarklet

You can also try the Google Mobilizer Bookmarklet to view just text of web pages

1
2

Install the AddOn "Absolute Enable Right Click & Copy", that enables everything that the other No Script AddOns can not.

1

Several of the solutions proposed might be browser specific, so it's worth suggesting a few alternatives:

  1. Use a broswer that respects you more.

    a. Emacs has browsers emacs-w3m and eww that will always allow one to select text.

    b. Other text-based browsers such as lynx, elinks, and w3m, might allow one to select text, but even if not, if running those programs in a terminal window, one can select text using one's mouse. And, if one is using those programs from within tmux, one can use tmux's ability to copy text even without a mouse.

  2. Use a command line tool to download the entire url in a readable text format.

    a. w3m -dump [your_url] > your_file.txt

    b. lynx -dump [your_url] > your_file.txt. I usually prefer this one because it marks hyperlinks as readable footnotes!

1

Just create the following css style:

html, body {
    user-select: text;
}

There is an extension called Stylish which allows you to install that (or any other) css code in any website of your choice. Just type in the above css code and tell which website[s] you want it to be applied to and you are good to go. This extension works on Chrome, Baidu, Firefox and Opera. If you happen to be on IE then you are out of luck. But you already know that don't you.

1

Another possibility to deactivate the selection is to use the property onselectstart, as explained by Ismael Miguel:

Another way is to add onselectstart="return false;" to the body. Some other techniques (like, removing the selection with JavaScript) work as well. – Ismael Miguel Jan 6 '18 at 12:07

Via the Developer Tools of Chrome, I could dynamically remove the selectstart event handler and then could select the text (and hopefully use Ctrl+C which was not disabled).

1
  • You may, in addition, have oncopy="return false;" as an attribute.
    – g.a
    Commented Dec 13, 2022 at 7:34
1

If you want to disable a website from blocking you from selecting text, try the following:

  • Inspect the website using developer tools.
  • Locate the <head></head> block.
  • Select the <head></head> block.
  • Press the delete key.

Since the <head /> typically contains the CSS links, you'll be removing the styling that disables you from selecting text.

0

I saved the web page and then opened it in MS Word. Although that removed some formatting, it allowed me to select and copy the text. An annoying but relatively easy workaround.

1
0

I had a similar problem with a parcel-tracking site which had some Chinese writing I needed to translate.

So I saved the page as a pdf and could then select and copy anything I needed in the pdf! (I'm using Ubuntu with print to pdf).

0

I found a different way to disable selecting with CSS:

  pointer-events: none;

Disabling that property with the developer tools on the node I wanted to copy text from made it work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .