开窗器焦点或活动 [英] window opener focus, or active

查看:89
本文介绍了开窗器焦点或活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在新标签页面中打开一个窗口,但是当我希望该开启者页面处于活动状态时,而不是新的。我怎么能这样做...非常感谢

i want to open a window in a new tab, but when i want that opener page to be active, not the new one. How can i do this... Many thanks

我的代码是这样的:

  <script language="javascript">
  window.open("http://www.google.ro");
  window.opener.location.focus();
  </script>


推荐答案

将焦点放在新窗口上(但你不要不想这样,它默认可能会有焦点):

To give focus to the new window (but you don't want that, and it will probably have focus by default):

var newWindow = window.open("http://www.google.ro", '_blank');
newWindow.focus();

我认为不可能从新打开的标签中窃取焦点。我没有找到任何官方声明告诉我,但我在这个主题上发现的所有文章都谈到配置浏览器默认情况下打开标签而没有焦点。

I don't think it's possible to steal the focus from the new opened tabs. I didn't find any official statement telling this, but all the articles I found on this subject talk about configuring your browser to open tabs by default without focus.

我能想到的唯一解决方案就是这个:

The only "solution" I could come up with is this one:

window.open("http://google.com", "_blank");
window.alert('Hello there! This is a message that annoys you, the user.');

请注意,打开弹出窗口时可以转移焦点。

了解有关的更多信息窗口对象。

非主题说明:此答案获得以最初完全不正确的形式投票2次证实了我的怀疑,即大多数SO用户只是盲目地投票,并根据回答的人有多少声誉。

这篇关于开窗器焦点或活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆