Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the [object Window]?

Tags:

javascript

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 ..

like image 782
mrdaliri Avatar asked Mar 02 '11 21:03

mrdaliri


People also ask

What is object window in JavaScript?

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.

What are different types of window objects?

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.

Which level of object is window object?

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.


1 Answers

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.

like image 111
Matthew Flaschen Avatar answered Sep 28 '22 08:09

Matthew Flaschen