打开新窗口的书签将当前窗口转发到[对象窗口]?
我正在使用一个小书签,它在新窗口中打开网页。它在 Chrome 上运行正常。
但是,当我在 Firefox 中使用相同的内容时,它会打开一个包含新网页的新窗口,但单击此书签的页面将转发到带有文本 [object Window]
的某个页面。我该如何解决这个问题?
我的代码:
<a href="javascript:open('http://www.google.com','targetname','height=500,width=500');">Bookmarklet</a>
请让我知道如何解决这个问题。
谢谢
I am using a small bookmarklet which opens a webpage in a new window. It works properly on chrome.
However, when I use the same in Firefox it opens a new window with new web page but the page on which this bookmarklet was clicked is forwarded to some page with text [object Window]
. How do I solve this issue?
My code:
<a href="javascript:open('http://www.google.com','targetname','height=500,width=500');">Bookmarklet</a>
Please let me know how to solve this issue.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须“吃掉”JavaScript URL 中的最后一个返回值,返回任何
typeof returnValue != 'undefined'
都相当于调用document.write(returnValue)
。并且window.open
返回新创建的window
对象,因此输出“[object Window]”。当然,您可以通过无意识地附加void(0)
语句来做到这一点,但它太笨拙了。无魔法版本(返回值被吃掉,调用窗口不受干扰):您很可能会扩展您的书签,因此为了防止混乱的全局范围,您最好采用匿名函数方式(注意没有
return
声明):You have to "eat" last return value in the JavaScript URL, returning anything
typeof returnValue != 'undefined'
will be equivalent to invokingdocument.write(returnValue)
. Andwindow.open
returns newly createdwindow
object, hence the output of "[object Window]". Surely, you can do that by mindlessly appendingvoid(0)
statement, but it is SO clumsy. No-magic version (return value eaten, calling window left undisturbed):You are likely will expand your bookmarklet, so to prevent cluttering global scope, you'd better go anonymous function way (note the absence of
return
statement):试试这个代码,我添加了“void(0);”单击后停止父窗口消失。
Try this code, I have added "void(0);" to stop the parent window go away after clicked.