Skip to content
Advertisement

what is the [object Window]?

Google Translate, has some bookmark let for translate with 1 click, for example:

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

This javascript code, opens the translator page in the current page (target=_self), but I want it opens a new window (tab) for translate. so changed to:

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

My problem is here: when I run that code, it opens a new window for translate, and do it; but the non-english page content replaced with [object Window], but I don’t want to change original page content …

What Can I DO?

Thank you ..

Advertisement

Answer

Add void(0) at the end, so there will be no value. If the last expression has a value (in this case a window), the page is replaced with it.

Advertisement