2011-03-02 120 views
3

谷歌翻译,有一些书签,让与1次点击翻译,例如:什么是[对象窗口]?

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;}; 

这段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);}; 

我的问题就在这里:当我运行的代码,它打开了翻译一个新的窗口,并做到这一点;但非英文页面内容被替换为[object Window],但我不想更改原始页面内容...

我该怎么办?

谢谢。

回答

8

末添加void(0),所以也就没有价值。如果最后一个表达式有一个值(在这种情况下是一个窗口),则页面被替换。

+0

它的工作原理,谢谢 – gcivan 2014-01-14 08:38:59

相关问题