views:

54

answers:

0

Hi its a browser(IE) issue

i have a code and its does highlight on selected text....its working fine but when i m selecting text that already selected then its not highlighted(Selected) on IE7/8

plz see code below

if (window.getSelection) //Firefox { range = window.getSelection().getRangeAt(0); var sel = window.getSelection(); document.designMode = "on"; if (range) { sel.removeAllRanges(); sel.addRange(range); }

// Use HiliteColor since some browsers apply BackColor to the whole block 
   if ( !document.execCommand("CreateLink", false, "HIGHLIGHT_CREATELINK") ) { 
       document.execCommand("CreateLink", false, "HIGHLIGHT_CREATELINK"); 
   } 

   jQuery('a[href="HIGHLIGHT_CREATELINK"]').css({'backgroundColor' : 'yellow' , 'color' : 'black'});
   jQuery('a[href="HIGHLIGHT_CREATELINK"]').attr("id",id_val); 

 jQuery('a[href="HIGHLIGHT_CREATELINK"]').hover(function(d) { 
    ShowHighlighter("deleteHighlight",id_val); 
 }, function(d) { 
      HideContentFade("deleteHighlight"); 
 }); 
    document.designMode = "off"; 
}
else if (document.getSelection)
{
    txt = document.getSelection();

} else if (document.selection) //IE {

  range = document.selection.createRange();

// need some solution for over lapping case

     var ret = range.execCommand("CreateLink", false, "HIGHLIGHT_CREATELINK");
     jQuery('a[href="HIGHLIGHT_CREATELINK"]').css({'backgroundColor' : 'yellow' , 'color' : 'black'});

     jQuery('a[href="HIGHLIGHT_CREATELINK"]').css({'backgroundColor' : 'yellow' , 'color' : 'black'});
     jQuery('a[href="HIGHLIGHT_CREATELINK"]').attr("id",id_val); 

    jQuery('a[href="HIGHLIGHT_CREATELINK"]').hover(function(d) { 
      ShowHighlighter("deleteHighlight",id_val); 
  }, function(d) { 
       HideContentFade("deleteHighlight"); 
  }); 

}