javascript - [对象窗口]是什么?

标签 javascript

谷歌翻译,有一些书签可以一键翻译,例如:

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/

相关文章:

javascript - 如何为一般元素设置背景颜色,然后通过一个事件(onclick)设置特定元素(同类)的背景颜色?

Javascript 扩展文本淡入

如果位移太多,Javascript 数字将重置为 0

javascript - 在 Google Scripts 自定义函数中接受任意数量的参数?

Javascript 或 JQuery 字符串获取具有特定前缀的子字符串

javascript - 单击当前页面上的链接后保持菜单项处于事件状态

javascript - 当我将鼠标悬停在下拉列表中的项目上时,如何让 JQuery 工具提示显示?

javascript - 如何防止 Vuex 干扰我的类实例?

javascript - Chart Js图上标记X值

javascript - 如何使用 ngfor 循环显示数组中的每个组件