javascript 什么是[对象窗口]?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5173996/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
what is the [object Window]?
提问by mrdaliri
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 代码在当前页面(目标 = _self)中打开翻译器页面,但我希望它打开一个新窗口(选项卡)进行翻译。所以改为:
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 ...
我的问题在这里:当我运行该代码时,它会打开一个新窗口进行翻译,然后执行;但非英文页面内容替换为[object Window],但我不想更改原始页面内容...
What Can I DO?
我能做什么?
Thank you ..
谢谢 ..
回答by Matthew Flaschen
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.
添加void(0)在最后,所以将没有价值。如果最后一个表达式有一个值(在这种情况下是一个窗口),页面将被替换。

