如何让 window.focus() 在 Firefox 中工作 [英] How to get window.focus() to work in firefox

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

问题描述

有人知道如何在 FireFox 中使用 window.focus() 吗?(27.0.1).我已经尝试了所有 about:config 设置,但仍然没有运气.

Does anyone have a clue on how to be able to use window.focus() in FireFox? (27.0.1). I have tried all the about:config settings out there but still no luck.

我的代码如下所示:

var wi = window.open('myUrl');
wi.focus();

== 编辑 ==

我正在尝试在我的机器上的 FireFox 中进行这项工作,不适用于任何其他用户,所以请避免标准让您的用户决定"或这取决于用户的设置"作为我想让它为本地项目工作:)

I'm trying to make this work in FireFox on my machine, not for any other users so please refrain from the standard "let your users decide" or "it depends on the user's settings" as I want to get this to work for a local project :)

推荐答案

工具 > 选项、内容区域、启用 JavaScript"右侧的高级"按钮应该为您提供允许此行为的选项.如果您使用的是 Linux,导航可能会略有不同.

Tools > Options, Content area, "Advanced" button to the right of "Enable JavaScript" should give you the option to allow this behavior. If you're on Linux, the navigation might be slightly different.

请注意,允许用户选择应该聚焦的窗口通常被认为是最佳做法.

Note, it is generally considered best practice to allow the user to choose what window should be in focus.

这是 about:config 你指的是:dom.disable_window_flip

This is about:config you're referring to: dom.disable_window_flip

在 FF 27.0.1 中,我可以通过向 window.open 提供窗口名称和选项参数,然后调用 focus 来打开一个具有焦点的新窗口.

In FF 27.0.1 I am able to open a new window with focus by providing window name and option parameters to window.open, and then calling focus.

var wi = window.open('http://www.google.com', 'window_name', 'height=200,width=200');
wi.focus();

示例:http://jsfiddle.net/CLVh2/

对于 Chrome 支持,您需要查看:​​Google Chromewindow.open";解决方法?

For Chrome support, you'll want to check out: Google Chrome "window.open" workaround?

用于标签支持

如果你想打开一个标签并在 FF (27.0.1) 中给标签焦点,并且仅仅调用 window.open('url') 并没有给你想要的结果,请尝试检查当我打开一个新标签,立即切换到它"选项.它可以在工具>选项>标签

If you want to open a tab and give the tab focus in FF (27.0.1), and simply calling window.open('url') is not giving you the desired result, try checking the "When I open a new tab, switch to it immediately" option. It can be found in Tools > Options > Tabs

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

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