1

I'm working on what is basically a small utility that displays a piece of sourcecode in a table which has two columns, one for line numbers and one for the actual source.

I found that you can prevent the appearance of text being selected with the following CSS:

table th {
    -moz-user-select: none;
    -webkit-user-select: none;
}

Unfortunately this doesn't work. While the text appears not to be selected, if you copy and paste is will still copy it.

So is there actually a way to do this?

4 Answers4

0

What is selected depends on order in the DOM tree. Therefore, you need to place your source display before or after the html that displays line numbers. Putting the source and line numbers in separate divs and floating your elements is probably the easiest way to accomplish this.

geowa4
  • 40,390
  • 17
  • 88
  • 107
0

A solution to your problem can be found here:

Line numbering and copy/paste (HTML/CSS)

Community
  • 1
  • 1
bytebrite
  • 2,396
  • 2
  • 14
  • 3
-1

All of your line numbers should reside within a single td in a single tr. If you create one tr for every line, you will be unable to prevent the copying of the line numbers.

See the source of this page: http://pastie.org/561138 for an example.

hobodave
  • 28,925
  • 4
  • 72
  • 77
  • He's trying to display line-numbers on the side so people can copy and paste code without getting the numbers. Read>comprehend>answer. – Sneakyness Jul 28 '09 at 01:34
  • I think that it is very difficult to tell what asker is looking for. – geowa4 Jul 28 '09 at 01:43
  • I'd probably go with an overlay of some kind to prevent highlighting, if that were the intent. – geowa4 Jul 28 '09 at 01:46
-1

Have you tried putting them in a separate div and floating it?

I also just found this, uses jQuery to do it for you. You could use it, or you could take it apart and figure out how it displays it, and then use that.

Sneakyness
  • 5,305
  • 4
  • 33
  • 39
  • JS should be used as a last resort for matters like this. Still good to provide options though. – geowa4 Jul 28 '09 at 01:45
  • Which is why I suggested using it to get the desired end result, and see the code required to do such a thing. – Sneakyness Jul 28 '09 at 01:54