谷歌翻译,有一些书签可以一键翻译,例如:
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 代码在当前页面 (target=_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]
,但是我不想改变原来的页面内容...
我能做什么?
谢谢..
最佳答案
在最后加上void(0)
,这样就没有值了。如果最后一个表达式有一个值(在本例中是一个窗口),页面将被它替换。
关于javascript - [对象窗口]是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5173996/