118

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.

Kodiologist
  • 113
  • 7
user6329530
  • 1,321
  • 2
  • 9
  • 8
  • 12
    *"How do websites block marking of text"* - They set `style.userSelect` to `none`. –  Jan 05 '18 at 09:52
  • 1
    Do you want to duplicate the blocking on your own site? Or just copy this text? Look at the source & copy it from there yet? – Xen2050 Jan 05 '18 at 09:57
  • 5
    @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. – user6329530 Jan 05 '18 at 13:47
  • 147
    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 Jan 05 '18 at 15:17
  • 3
    I don't know how prevalent the practice is anymore, but I remember running across a few instances of a single-pixel image being stretched to cover the whole page to prevent copying of text etc. That and changing my mouse pointer to glittery rainbow-unicorn-stars along with flashing text everywhere... – RIanGillis Jan 05 '18 at 16:18
  • With JavaScript. Use Lynx as browser. – mirabilos Jan 05 '18 at 17:50
  • 41
    @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 Jan 05 '18 at 20:39
  • 1
    Install RightToCopy – anna328p Jan 05 '18 at 20:47
  • There's a chrome addon that unblocks pasting, I'm sure there's one for unblocking selection and copying too. – Kevin Jan 05 '18 at 23:35
  • @mvw I think New York Times https://www.nytimes.com and Institutional Investor https://www.institutionalinvestor.com/ are additional example sites. – Ellie Kesselman Jan 07 '18 at 16:05
  • 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 Jan 07 '18 at 21:12
  • @DVK +1000 for the much needed focus on real life. However part of the problem is that wishful thinkers often adopt this kind of measures and then expect these measures to "solve the problem", and if a developer humbly points out that they only make the content stealing require a bit more work, he/she is frowned upon as non-positive, not a doer etc. So it's still good that people point out that this approach is not a good security measure, they should just add something like "although it does mitigate the problem a lot". Then it depends on what level of protection the specific business needs. – SantiBailors Jan 08 '18 at 11:33
  • 1
    @MCMastery That's an awfully insular viewpoint. The correct assumption would be "Can we just take a moment and sympathize for all the delusional website owners out there who think their precious website content can be protected in any capacity whatsoever? And a moment of silence for the developer which was tasked in programming enough security to fool the owner." – MonkeyZeus Jan 08 '18 at 13:31
  • Seems that the example site doesn't block text selecting more. Nice. – Jeffrey C Apr 20 '21 at 06:17

16 Answers16

102

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!

chicks
  • 556
  • 4
  • 14
TOOGAM
  • 15,243
  • 4
  • 41
  • 58
  • 67
    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 Jan 05 '18 at 14:00
  • 1
    Thank you, @phihag, for the helpful other point of view. Still doesn't sway my disappointment seeing the major browsers implementing this as default behavior affecting my general computing (on a full-sized computer). Over the years, makers of major web browsers made other decisions I've disagreed with, and I've learned to accept the idea that they have some different opinions than I do. Even so, when I see them do things like (by default) taking control away from the user (and giving it to webmasters instead), my understanding of this reality doesn't mean I can't be still disappointed. – TOOGAM Jan 05 '18 at 15:14
  • 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... – Sean Burton Jan 05 '18 at 15:18
  • 1
    This should be quite easy in Greasemonkey – Chris H Jan 05 '18 at 15:22
  • 1
    @TOOGAM It's not right to lay the blame at the "major browsers" for enabling it by default. The browser's job is to display/ perform whatever features it comes across in a page's code, not debate if it should be there or not. If you want to blame someone then you should probably point the finger at the restrictive design choices made by the dev's/designers and the way that they implement said features. – Sean T Jan 05 '18 at 16:10
  • 2
    @SeanBurton if you view the webmaster as a "user" of a browser, then it makes sense to allow them to enable features. But if you view a browser as existing solely to serve the person looking at webpages, then it should be up to them as to whether a feature should be enabled. – Acccumulation Jan 05 '18 at 16:11
  • 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. – Acccumulation Jan 05 '18 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? – Sean Burton Jan 05 '18 at 16:16
  • 2
  • 13
    @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 Jan 05 '18 at 16:57
  • 1
    @SeanBurton First you say that this 'doesn't sound like "by default" to me', then you say that if it's not enabled by default then it's essentially useless. – Acccumulation Jan 05 '18 at 19:28
  • 3
    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 06 '18 at 12:07
  • @SeanBurton: The line is drawn here: proper interface presumes that users have full control over how the browser renders things. Based on that line, disabling users from standard actions seems wrong. MS IE has an option about whether images are displayed, and ***if*** that is ever unchecked then, ***yes***, the user must (re-)enable them. My thoughts about "by default" referred to the idea that Firefox and Chrome's built-in Dev Tools would allow the user to override the CSS, so disabling the user's ability to select is the default action (but can be overridden easily-ish, thanks to dev tools) – TOOGAM Jan 06 '18 at 13:33
  • 2
    @SeanT - I view the browser's job as serving the user to let the user see rendered code in the way that the user desires. The web page's code instructs the browser what is desired, but the browser decides, and it is not the browser's job to perform whatever the page's code says, because the browser serves the user, not the web server (or webmaster/page designer). If a menu shows some unicode/emoji that I want to copy and paste into Google to find out the character's code, I don't like JavaScript/CSS trying to disable my ability to easily select text if that's what I'm trying to do. – TOOGAM Jan 06 '18 at 13:39
  • Oh, and to add to my last comment to @SeanBurton... At the time I said "by default" (but I forgot when I made my last comment), I was also thinking that in addition to Dev Tools, add-ons or Javascriptlets (bookmarks containing JavaScript code) could also be used (and would probably be a lot easier than Dev Tools). Kevin's comment in the question suggests such a thing (and reminded me). – TOOGAM Jan 06 '18 at 13:53
  • 3
    Another detail is to keep in mind that HTML isn't just for web. There are plenty of games that use it for the interface, where selecting text doesn't make sense and where the user will click and drag the mouse for various reasons. – William Jan 07 '18 at 15:59
  • 2
    Well, [this](https://i.imgur.com/eYOLGVh.png) is what happens when the developer forgets to disable selection (that's a UI built with web technologies). If you want your app to feel like an actual app and not a text document, disabling selection is the way to go. But doing this on a website is a very poor design choice. – Lucas Trzesniewski Jan 07 '18 at 20:25
  • @phihag Browsers already do this without CSS, links have a larger hit target than the link itself when touched. Sometimes to the point of being annoying and you have to zoom when you actually want to select text because the browser is trying to be too helpful. – Anders Jan 08 '18 at 02:22
36

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.

Herohtar
  • 798
  • 4
  • 11
  • 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? – Hashim Aziz Jan 09 '18 at 03: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 Jan 09 '18 at 03: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 Jan 27 '22 at 04:35
  • This site brought me here https://www.hildastouchofspice.com/2011/12/marzipan.html#prettyPhoto . The above answer plus https://superuser.com/a/964711/617826 does the trick. – DannyBoi Dec 17 '22 at 04:02
15

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

JMK
  • 3,280
  • 9
  • 47
  • 71
13

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

enter image description here

Oliver Salzburg
  • 86,445
  • 63
  • 260
  • 306
  • 1
    Neat trick, for those who don't want to install yet another extension or meddle with the developer tools console. – Simón Nov 19 '22 at 21:46
11

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.

Eric Duminil
  • 208
  • 2
  • 7
  • 1
    Yeap, it works also on IE11. – Marco Demaio Feb 20 '18 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 Nov 22 '22 at 19:04
9

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.

DarkDiamond
  • 1,875
  • 11
  • 12
  • 19
and his dog
  • 377
  • 1
  • 5
  • 15
  • Works great! This should be the new accepted answer – towe Feb 04 '22 at 08: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 Jul 11 '22 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 Dec 27 '22 at 17:10
  • Best solution for the challenged and lazy @rses ^_^ – Whoever Jan 01 '23 at 13:43
  • Works perfect. Thank for saving time and effort. – invinciblemuffi May 15 '23 at 08:48
5

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.

Arjan
  • 30,974
  • 14
  • 75
  • 112
derei
  • 51
  • 1
  • 5
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;
  }
}
Obsidian Phoenix
  • 447
  • 2
  • 4
  • 16
  • Adding webkit and ms prefixes for something that will only run on firefox is a bit... redundant. – Stephan Bijzitter Jan 08 '18 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. – Obsidian Phoenix Jan 08 '18 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

mvark
  • 2,410
  • 1
  • 17
  • 21
  • I just used this bookmarklet to allow copying of my entire Netflix watch list with images and everything into a Thunderbird email: https://gist.github.com/duzun/d66c775a39a5be9fb519/stargazers – Dreamspace President Jul 24 '21 at 20:09
2

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!

user1404316
  • 133
  • 4
2

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

Chris
  • 21
  • 1
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.

agcala
  • 123
  • 4
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).

Sandra Rossi
  • 215
  • 1
  • 12
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.

John
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://superuser.com/help/whats-reputation) you will be able to [comment on any post](https://superuser.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/1122466) – Toto May 03 '22 at 16:49
0

For my part, i just delete the < Head > section and all the text was not formated but selectable

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).

Eric
  • 1
  • 1