Anonymous 0

I've been using this (working) bookmarklet as a template

 javascript:var%20t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var%20e=(document.charset||document.characterSet);if(t!=''){location.href='http://translate.google.com/translate_t?text='+t+'&hl=en&langpair=auto|en&tbb=1&ie='+e;}else{location.href='http://translate.google.com/translate?u='+escape(location.href)+'&hl=en&langpair=auto|en&tbb=1&ie='+e;};

What that does is translate highlighted text into English suing detect language.

What I want to do is search for highlighted text on a search engine of my choice (twitter) . This is what I have so far:

javascript:var%20t=((window.getSelection&&window.getSelection())||(document.getSelection&&document.getSelection())||(document.selection&&document.selection.createRange&&document.selection.createRange().text));var%20e=(document.charset||document.characterSet);if(t!=''){location.href='http://twitter.com/#search?q='+e'};

Error console says "Unterminated string literal"

2 answers

Ktash 1851
0
points
This was chosen as the best answer

You have a trailing ' at the end of your statement, after your +e. Remove that and it should work. Also, at the end, it should be +t not +e because e is your charset while t is your selected text.

Answered over 8 years ago by Ktash
0
points

What would I need to add so that it open a new tab and does the search there? Also would it be possible to use and event handler instead like on.click? Does on on.doubleclick exist ? I'd use a userscript for the event handler version.

Answered over 8 years ago by BDAdams