Flash窃取浏览器焦点 [英] Flash steals browser focus

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

问题描述

我在我的页面中有一个Flash应用程序,当用户与Flash应用程序交互时,浏览器/ html / javascript停止接收键盘输入。



例如,在Firefox中,控制-t不再打开一个新的标签。

然而,如果我点击浏览器开始接收这些事件。



是否有编程方式(通过flash或javascript)返回焦点到浏览器?



当用户在Flash中点击一个按钮后,我有Flash执行一个JavaScript回调,所以我已经尝试给焦点的表单字段通过javascript,但这种做法似乎并没有工作。

一个也许更具体的例子是Youtube。他们也有这个问题。当我点击播放/暂停按钮或者调整音量时,我希望我的浏览器键盘控制仍然可以工作,但是他们没有,我必须点击电影区域以外的页面。这是我试图解决的确切问题。

解决方案

您可以使用Flash中的ExternalInterface类来调用JavaScript。例如,你可以设置一个间隔函数(例如Event.ENTER_FRAME)来调用@Diodeus提到的JavaScript函数:

pre $ $ $ $ C> document.body.focus();

或者,更好的解决方案是将一个事件侦听器添加到flash根目录听听鼠标何时离开Flash。你可以设置这个事件来把焦点移到document.body。

AS3

  package {
import flash.display。*;
导入flash.events。*;
import flash.external.ExternalInterface;

public class TestMouseLeave extends Sprite
{
public function TestMouseLeave()
{
//添加鼠标事件监听器LEAVES FLASH
addEventListener(MouseEvent.MOUSE_OUT,onMouseLeave);

$ b $ private function onMouseLeave(ev:Event):void
{
var jslink = new ExternalInterface();
jslink.call(changeFocus);



$ b $ / code $ / pre
$ b

您的网页:

 < script type =text / javascriptlanguage =javascript> 
function changeFocus(){
document.body.focus();
}
< / script>

让我知道你是否想要一个AS2的例子,然后我把它贴出来。



想要记录下这个解决方案:一旦你将焦点推回到浏览器,你将需要用户再次点击Flash插件来激活用户在Flash插件里面输入。这可能是一个令人震惊的用户体验,并且在使用此解决方案时需要考虑。


I have a flash app in my page, and when a user interacts with the flash app, the browser/html/javascript stops receiving keyboard input.

For example, in Firefox control-t no longer opens a new tab.

However, if I click on part of the page that isn't flash, the browser starts receiving these events again.

Is there anyway to programatically (either through flash or javascript) to return focus to the browser?

After the user clicks a button in flash, I have the flash executing a javascript callback, so I've tried giving focus to a form field (and to the body) through javascript, but that approach doesn't seem to be working.

A perhaps more concrete example is Youtube. They also have this problem. When I click the play/pause button, or adjust the volume, I would expect my browser keyboard controls to still work, but they don't, I have to click somewhere on the page outside the movie area. This is the exact problem I'm trying to solve.

解决方案

You can use the ExternalInterface class within Flash to call JavaScript. For example you could set up a function on an interval (Event.ENTER_FRAME for example) to call the JavaScript function that @Diodeus mentioned:

document.body.focus();

Or, an even better solution would be to add an event listener to the flash root (stage) to listen for when the mouse leaves Flash. You can set up this event to move focus to the document.body.

AS3

package {
   import flash.display.*;
   import flash.events.*;
   import flash.external.ExternalInterface;

    public class TestMouseLeave extends Sprite
    {
        public function TestMouseLeave()
        {
            // Add event listener for when the mouse LEAVES FLASH
            addEventListener(MouseEvent.MOUSE_OUT, onMouseLeave);
        }

        private function onMouseLeave(ev:Event):void
        {
            var jslink = new ExternalInterface();
            jslink.call("changeFocus");
        }
    }

}

Javascript on your page:

<script type="text/javascript" language="javascript">
    function changeFocus(){
        document.body.focus();
    }
</script>

Let me know if you want an AS2 example, and I'll post it up.

Wanted to make a note about this solution: Once you push focus back to the browser, you will require that the user click on the Flash plug-in again to activate user input inside the flash plug-in. This could be a jarring user experience, and is something to consider when using this solution.

这篇关于Flash窃取浏览器焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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