Sunday, January 14, 2007

Javascript selecting text with bookmarklet example

Here is a example of selecting text in Javascript. I've create a bookmarklet that let you search a word in dictionary.com. Just remove tabs and newline.

javascript:(
function(){
var str="";
if(window.getSelection){
str=window.getSelection();
} else if(document.getSelection){
str=document.getSelection();
} else if(document.selection){
str=document.selection.createRange().text;
}
var d=window.open("http://dictionary.reference.com/" +
"search?q="+str,"dictionary","1");
window.setTimeout(function(){d.focus()},300);
}
)()

No comments:

Post a Comment