window.opener.focus()不工作 [英] window.opener.focus() doesn't work

查看:1623
本文介绍了window.opener.focus()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法得到这个工作。

I can't seem to get this to work.

在响应点击,窗口中的窗口打开B(然后具有焦点)。然后,响应第B点击,窗口的呼叫 window.opener.focus(),但重点做的的回到A

In response to a click, window A opens window B (which then has focus). Then, in response to a click on B, the window calls window.opener.focus(), but the focus does not go back to A.

我已经找到了Chrome浏览器奇怪,奇怪的解决方法(29,可能还有其他)。
如果我运行:

I have found a strange, strange workaround for Chrome (29, possibly others). If I run:

window.opener.name = 'somename';
window.open(window.opener.location.href, window.opener.name);
window.opener.focus();

它的工作(而不会重新加载窗A)。但是,这并不适用于Firefox的工作,它可能是侥幸呢。

it does work (and doesn't reload window A). But this doesn't work for Firefox, and it is probably a fluke anyway.

这似乎很清楚,我是什么揭幕战焦点应该的做,但 window.opener.focus()不起作用。我缺少什么?

It seems very clear to me what opener and focus are supposed to do, but window.opener.focus() doesn't work. What am I missing?

推荐答案

从的精细的手工

打造一个请求以使窗口前面。这可能会由于用户设置,并不能保证窗口此方法返回之前最前面。

Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.

重点煤矿。调用焦点()只是一个请求,浏览器可以随意地忽略你,你通常应该会被忽略。想想你可以得到什么样的邪恶的东西通过将焦点切换到小窗户,而有人打字,如果你需要一些原因,浏览器会忽略你的要求。

Emphasis mine. Calling focus() is just a request and the browser is free to ignore you and you should generally expect to be ignored. Consider what sorts of nefarious things you could get up to by switching focus to a tiny window while someone is typing if you need some reasons why a browser would ignore your request.

如果您需要焦点()来为你的应用程序中工作的工作,那么你需要重新设计应用程序,以便它不需要调用焦点()

If you need focus() to work for your application to work then you need to redesign your application so that it doesn't need to call focus().

这篇关于window.opener.focus()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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