SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Left-click text highlight - I know its possible, but how?

    Hi guys,
    I know there is a way to manipulate left click text highlighting in javascript. At lest these guys did it. Does anyone know the basic mechanism of text highlight manipulation? I could not find the answer on the web.

    Thank you for input.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone?

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Wel if it helps, here is how they do it.

    Code javascript:
    Webliter.prototype.highlight=function(){
    	var blockHTML='';
    	window.selection=window.getSelection();
    	var tmp_text=selection+'';
    	if(window.selection&&tmp_text.length>0){
    		var tmp=this.viewPartialSourceForSelection(window.getSelection());
    		var blockHTML=tmp.innerHTML;
    		blockHTML=blockHTML.substr(blockHTML.indexOf(this.MARK_SELECTION_START)+this.MARK_SELECTION_START.length);
    		blockHTML=blockHTML.substr(0,blockHTML.indexOf(this.MARK_SELECTION_END));
    	}
    	return blockHTML;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, Paul. It helps. From this snippet I was able to google myself to this article.


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
  •