我的书签打开一个新窗口,如果该窗口已经打开,我想调用 .focus()
我有一个打开新窗口的书签:
<a href="javascript:void(window.open(
'http://localhost:8080/myapp/query.jsp?u='+encodeURIComponent(location.href)+'t='+encodeURIComponent(document.title),
'query','status=0,toolbar=0,location=0,menubar=0,resizable=false,scrollbars=false,height=600,width=410'
));query.focus();">MyApp</a>
当窗口未打开时,它可以正常工作,因为它被打开并且可见。
但是,如果窗口已经打开并且我单击书签,我希望现有窗口成为焦点并处理提交的新数据(如果页面不同)。
您可以看到我尝试使用 query.focus();
执行此操作,但这似乎不起作用。
I have a bookmarklet that opens up a new window:
<a href="javascript:void(window.open(
'http://localhost:8080/myapp/query.jsp?u='+encodeURIComponent(location.href)+'t='+encodeURIComponent(document.title),
'query','status=0,toolbar=0,location=0,menubar=0,resizable=false,scrollbars=false,height=600,width=410'
));query.focus();">MyApp</a>
When the window is not open, this works fine as it gets opened and is visible.
But if the window was already open and I click the bookmarklet, I want the existing window to be made in focus and have the new data that is submitted be processed (if the page is different).
You can see I have tried to do this with query.focus();
but this doesn't seem to work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在
window.open()
返回的窗口上调用focus()
:Call
focus()
on the window returned bywindow.open()
: