SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is UnHighlightable Text Possible?

    I was just curios if anyone has ever tried to make it so you could not select certain text. If someone knows of a certain way to do it or can provide me with some information, that would be great.

    unselectable='on' keeps me from being able to select that text, however if I highlight a paragraph and the unselectable text it part of it, it still gets highlighted.
    Last edited by tmapm; Oct 16, 2003 at 10:08.

  2. #2
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try positioning a DIV tag with a transparent image over the text. set the z-index on the DIV tag higher than the text. I haven't tested this, but I suspect it would work.

    Also, check out the various Range type objects available through JS. You might be able to intercept highlighting in such a way. But it would be unreliable and subject to browser compatibility issues.

    This does work...
    Code:
    <html>
    <head>
    <title>test sel text</title>
    <style type="text/css">
    .abs { position: absolute; top: 0px; left: 0px; z-index: 10; }
    </style>
    </head>
    <body>
    here is text
    <div class="abs" id="blockDiv"><img src="silego.com/navbar/images/common/spacer.gif" width="100%" height="30" alt="can't highlight me!" /></div>
    </body>
    -ChaCha

  3. #3
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. It isn't exactly what I am looking for though. It is a workaround. Even if I still have text around it I can start at that text and continue to highlight up or down it still highlights it. I basically want it so you are unable to copy the text. Maybe that is more doable? Still allow it to be all highlighted but don't allow certain lines to be copied?

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I know why you're asking this. You can't stop someone stealing text - they can always view the source of the page and then copy it from there

    -Sam
    Sam Hastings

  5. #5
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right Satan. Not only that but they could always just retype it, were it an image or flash.

    What about expanding a transparent image 100% width and 1000 vertical. Then write js to make sure that the image stays at the top of the view box as the user scrolls? Imagine it is a glass that always covers the viewing area.

    Then use a frameset with a 0, 100% ratio. place js code in the 0 size frame that dynamically writes the text out to the main frame, which is covered by the transparent pixel?

    Of course, a user could always Lynx or Telnet to your site, get the frameset, then see the uri for the .js code, then download it directly. But that may be more work than they are willing to put into it, since I doubt the docs are classified.
    -ChaCha

  6. #6
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Devilware.net: Basically I'm not trying to keep people from stealing text [img]images/smilies/smile.gif[/img] I have code that I print out and line numbers in front. What I am trying to do is to keep the line numbers from being highlighted so you can copy the code cleanly without the line numbers.

    I have used two <div> before that overlap, but then the line numbers are screwed when 1 line of code gets placed on a second line because of your res. Is it possible to have a DIV that will stay the same height as the next one?

    D- 1 D - Text Text TextD-
    2 D - Text Text Text
    Text Text Text
    D- 3 D - Text Text Text

  7. #7
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,254
    Mentioned
    113 Post(s)
    Tagged
    1 Thread(s)
    Why bother. All they need to do is view source and they've got your text.

    All you'll end up doing is annoying people and driving them away from your site.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style

  8. #8
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put the line numbers and text in different td cells...
    Code:
    <html>
    <head>
    <title>fsd</title>
    </head>
    <body>
    <html>
    
    <table border="1">
    <tbody>
    <tr>
    	<td><pre>1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29</pre></td><td rowspan="20"><pre>	if ($opts{all}) {
    		if ($opts{print}) {
    			print "$dir/$file\n";
    		} else {
    			del ("$dir/$file");
    		}
    		$wait->();
    	} elsif ($file =~ /$filter/) {
    
    		if ($opts{print}) {
    			print "$dir/$file\n";
    		} else {
    			del ("$dir/$file");
    		}
    		$wait->();
    	}
    }
    
    sub del {
    	my $file = shift;
    	return unless -T $file && $file =~ /\.txt$/i;
    
    	print "unlinking $file..." if $opts{verbose};
    	unlink $file;
    	unless (-e $file) {
    		print "success.\n" if $opts{verbose};
    	} else {
    		print "failed.\n" if $opts{verbose};
    	}</pre></td>
    </tr>
    </tbody>
    </table>
    
    </html>
    -ChaCha

  9. #9
    SitePoint Wizard
    Join Date
    Mar 2002
    Location
    Bristol, UK
    Posts
    2,240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code above would work, but what happens when you have a long line of code that spans more than one line on the screen, such as:

    echo 'This is a very long string. Although it only takes up one physical line of code in the script, it spans more than one line when printed to the screen';

    or something like that

    -Sam
    Sam Hastings

  10. #10
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <body>
    <script>
    function writeCodeTable() {
    	var strTable = "<table border='1'><tbody><tr><td>";
    	var oLines = new Array ("line 1", "line really long line here line 2", "line 3");
    	var strNPre = "", strCPre = "";
    	var intMax = 30; //max characters per line
    
    	for (var i=0; i<oLines.length; i++) {
    	    strNPre += (i+1) + "\n";
    	    strCPre += "\n" + oLines[i].substring(0, intMax);
    	    if (oLines[i].length > intMax) {
    		strNPre += "\n";
    		strCPre += "<b> \\</b>\n";
    		strCPre += oLines[i].substring(intMax, oLines[i].length);
    	    }
    	}
    
    	strTable += "<pre>" + strNPre + "</pre></td><td><pre>" + strCPre + "</pre></td></tr></tbody></table>";
    	document.write (strTable);
    }
    </script>
    <body>
    <script>
    writeCodeTable();
    </script>
    </body>
    </html>
    of course you will have to store each line of code you want to generate as a separate array element.

    Sorry my js is rusty. I just fixed the substring stuff.
    -ChaCha

  11. #11
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know how to do it with tables, I wanted to do it with DIV or be cheap and put each line out.

    1: var oLines = new Array ("line 1", "line really long line here line 2", "line 3" );

    2: var oLines = new Array ("line 1", "line really long line here line 2", "line 3" );

    Which is why I didn't want to allow 1: 2: etc to be highlighted. I'll try that out though. If I have to use tables I guess I will.

  12. #12
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why does everyone adhere to this "Tables are evil" doctrine now? Sure it is possible to design a site without tables, but why? A table here and there doesn't hurt anything, in fact there are times (probably like this one) where tables are the appropriate tool. I get so sick of this DIVision, pardon the pun, between the "new school" css junkies and the "old school" html academia fogies. Can't we all just get along

    Tongue in cheek.
    -ChaCha

  13. #13
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    CA
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would probably be better to split the long string on the space before the word that runs over the limit. And impose some sort of logic, like not splitting on a quoted space or on a space that follows a keyword like "new".
    -ChaCha

  14. #14
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright, thanks I know tables aren't evil, I was just wondering if there was another way. This will work. Thanks for all your help.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •