开发者

Prevent scrolling in IE when flash has focus

开发者 https://www.devze.com 2023-03-09 01:27 出处:网络
I have a web page where users can play flash games. We are now making some changes to the page which requires the games to be embedded with wmode=transparent or wmode=opa开发者_Python百科que so that w

I have a web page where users can play flash games. We are now making some changes to the page which requires the games to be embedded with wmode=transparent or wmode=opa开发者_Python百科que so that we can show HTML elements on-top of the flash games. The problem is that in Internet Explorer (on all versions) the whole page scrolls if a user presses the up/down arrow keys. I've tried everything I can think of and I've spent a whole day searching for a solution without success.

So far I've tried putting the game inside a iframe and I tried disabling the up/down keys with JS, none of which solves my problem.

The requirements are: wmode has to be transparent or opaque and I can't modify the flash games.


The only way to prevent scrolling when using wmode=transparent in Flash is to prevent scrolling using the arrow keys for the whole page. This page summarizes it best.

Basically, when transparent mode is active, the keyboard events in IE are propagated through to the browser; I don't know how to prevent scrolling (haven't tested), but you'd basically have to prevent keyboard scrolling globally.

This discussion highlights a possible workaround for IE8, and an example of the implementation using jQuery here. I don't have a copy of IE on me right now, but it might be worth a try.

AFAIK, though, games in Flash usually don't work very well with wmode=transparent, since focus can be stolen without user interaction. Your best bet would be reworking the page so as not to require Flash to have HTML overlays (even YouTube avoids having transparent set on their page, and they own the whole content).


The user needs to focus the flash movie first before any key actions are intercepted. This is actually a good behaviour, and shouldn’t be changed.

It would be a good idea to somehow ask the user to focus the movie voluntarily, maybe by putting a bit start button on it which they need to click first. Then all key actions should be sent to Flash.


How about some JS magic, if it works.

http://api.jquery.com/keypress/

http://api.jquery.com/event.preventDefault/

Register a KeyPress event handler on the object/embed tags. Let's say you have flash object with id #flashobj

$('#flashobj').keypress( function(event) { event.preventDefault(); } );

Or, more tricky, if the binding on flash object/embed wouldn't work, you can bind the keypress on the whole window, and check something along the lines of:

if (event.target.tagName.toLower() == "object") ...

Mileage may vary, as I remember it event.target is not very reliable...

Hopefully, flash will catch the keyboard event, and the page will ignore it. I know you said you tried it, but your approach might have been different (I suggested two distinctly different ways to do it, one might work)


It seems that there is simply no way around this. We will just have to accept the fact that HTML stuff (FB like chat in our case) will hide behind flash games.

But I still hope somebody proves me wrong :)

0

精彩评论

暂无评论...
验证码 换一张
取 消