谷歌翻译,有一些书签允许翻译,点击一下,例如:
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;};
Run Code Online (Sandbox Code Playgroud)
这个javascript代码打开当前页面中的翻译页面(target = _self),但是我希望它打开一个新窗口(tab)进行翻译.所以改为:
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);};
Run Code Online (Sandbox Code Playgroud)
我的问题在于:当我运行该代码时,它会为翻译打开一个新窗口,然后执行此操作; 但非英文页面内容被替换[object Window],但我不想改变原始页面内容......
我能做什么?
谢谢 ..