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 ..
The window object is supported by all browsers. It represents the browser's window. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are properties of the window object. Global functions are methods of the window object.
Methods of window object displays the alert box containing message with ok button. displays the confirm dialog box containing message with ok and cancel button. displays a dialog box to get input from the user. opens the new window.
Window object is a top-level object in Client-Side JavaScript. Window object represents the browser's window. It represents an open window in a browser.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With