cross-browser way to get selection.
1 2 function getSel(){ 3 var w=window,d=document,gS='getSelection'; 4 return (''+(w[gS]?w[gS]():d[gS]?d[gS]():d.selection.createRange().text)).replace(/(^\s+|\s+$)/g,''); 5 }
DZone Snippets > em3zh3 > browser
12973 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 function getSel(){ 3 var w=window,d=document,gS='getSelection'; 4 return (''+(w[gS]?w[gS]():d[gS]?d[gS]():d.selection.createRange().text)).replace(/(^\s+|\s+$)/g,''); 5 }