Friday, April 8, 2011

javascript for new tab (CTRL+T), new window (CTRL+N)?

When flash has keyboard focus, CTRL+T (new tab) and CTRL+N (new window) are intercepted by flash.

Is there a way to pass these events through to the browser so that they work (opening new tab, opening new browser) OR is there a javascript command for these actions?

From stackoverflow
  • Closest you could get is to have ActionScript trigger Javascript to open a blank window to a blank URL

    // We abstract it in a function here in case we want to
    // change it later
    function openBlankWindow()
    {
       window.open( '' );
    }
    

    For most people, this will launch a new window or a new tab (depending on their browser preferences) but since it is being initiated by the web page, may be subject to pop-up blockers.

    There is no way to actually ask the browser to specifically do one of the two tasks you are asking about. I would be a security/annoyance nightmare if web pages had the permissions/privileges to do that.

    Daniel Lew : I don't think he wants to give Flash access to the browser so much as he wants normal browser functionality to work even inside of Flash.
    Peter Bailey : I know that, which is why the very first thing I said was "closest you could get". Allowing key-commands to bubble-up out of a flash movie to the browser is something only Adobe could fix.
    Daniel Lew : I was responding to your last paragraph, not the rest - the rest makes sense to me.
  • This is a long standing issue with Flash and browsers. (And I mean long - check out this eight-year-old bug on Mozilla browsers.) The problem is that Flash intercepts all input events, rather than the browser. It's sandboxed in its own environment, and doesn't pass events back to the browser.

    Conceptually, this isn't necessarily a bad thing. What happens when Flash wants to listen to a "ctrl + n" event? Should the browser take focus away from Flash because it uses that hotkey already? It'd be a real pain for Flash developers, that is for sure.

    There have been proposals on how to fix this issue that I've seen for particular browsers, but there's no catch-all solution. For example, this solution is referenced in the bug, but it obviously won't work the way you want (since the user will have to jump through quite a few hoops to get it working).

    So... no, for now. Would be really neat if this problem could be fixed.

    Ben Blank : "Should the browser take focus away from Flash because it uses that hotkey already?" — Yes! Flash is a "guest" in the browser's "house". And a particularly ill-behaved one, too. :-)
    Daniel Lew : Hahaha, I've never heard the guest analogy before for plugins, that's pretty awesome.
  • Peter Bailey is pretty much right on. But he didn't give much of example.

    Hopefully the example below will help people incorporate such functionality in our apps. Probably with a little work we could write a class to replicate most of the browser functionality. At least all that can be replicated via JavaScript. And just include it in our apps.

    http://thesaj.wordpress.com/2009/12/05/how-to-enable-cntrl-t-tab-in-flash/

0 comments:

Post a Comment