Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Cross Broswer Q - How to force flash to have focus...

Question posted by: paulcybulski (Newbie) on May 13th, 2008 04:22 PM
I want to have the flash document have focus when the page initially loads...so the user can use the mouse scroll wheel to zoom in and out on the map that is on stage...(without having to click inside the browser window first)...

Now, I have already gotten this to work with IE by using the following code...

Code: ( text )
  1. <body onLoad="window.document.eXfX.focus();">


But like I said, this only works in IE, and I cannot find any information on forcing focus in other browsers...and I do not know how I would decide which browser is being used...I'm fairly new to JS so bare with me...
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
acoder's Avatar
acoder
Site Moderator
10,420 Posts
May 14th, 2008
07:57 AM
#2

Re: Cross Broswer Q - How to force flash to have focus...
Can you show the HTML code that displays the Flash content?

Reply
paulcybulski's Avatar
paulcybulski
Newbie
24 Posts
May 14th, 2008
01:04 PM
#3

Re: Cross Broswer Q - How to force flash to have focus...
Code: ( text )
  1. <body onLoad="window.document.eXfX.focus();">
  2. <script type="text/javascript" src="swfobject.js"></script>
  3. <div id="flashcontent">
  4. <a href="http://www.macromedia.com/go/getflashplayer" target="_blank">Click here to download Macromedia Flash Player to view the content of the page! Once the install is complete click Refresh to view this page.</a>
  5. </div>
  6. <script type="text/javascript">
  7. var so = new SWFObject("blah.swf", "eXfX", "100%", "100%", "8", "#ffffff");
  8. so.write("flashcontent");
  9. </script>
  10. </body>

Reply
acoder's Avatar
acoder
Site Moderator
10,420 Posts
May 14th, 2008
01:40 PM
#4

Re: Cross Broswer Q - How to force flash to have focus...
"eXfX" (the second parameter to SWFObject) is the ID, not the name of the object/embed element, so you want to use document.getElementById("eXfX").focus().

Reply
paulcybulski's Avatar
paulcybulski
Newbie
24 Posts
May 14th, 2008
02:29 PM
#5

Re: Cross Broswer Q - How to force flash to have focus...
Quote:
Originally Posted by acoder
"eXfX" (the second parameter to SWFObject) is the ID, not the name of the object/embed element, so you want to use document.getElementById("eXfX").focus().


that code only works in IE...unfortunately FF doesn't treat it the same way and you still have to click the swf to give it focus...

Reply
acoder's Avatar
acoder
Site Moderator
10,420 Posts
May 14th, 2008
05:58 PM
#6

Re: Cross Broswer Q - How to force flash to have focus...
From this technote it appears that this only works in IE, so you'll have to use the first solution.

Reply
paulcybulski's Avatar
paulcybulski
Newbie
24 Posts
May 15th, 2008
03:46 PM
#7

Re: Cross Broswer Q - How to force flash to have focus...
Quote:
Originally Posted by acoder
From this technote it appears that this only works in IE, so you'll have to use the first solution.


so there is no way to do this in FF? Nothing that I have tried has worked!!!

Reply
acoder's Avatar
acoder
Site Moderator
10,420 Posts
May 16th, 2008
08:42 AM
#8

Re: Cross Broswer Q - How to force flash to have focus...
Well, there is a way, but it's probably not what you're looking for.

Quote:
Originally Posted by from TechNote
There are two ways to give focus to the Flash movie.

* Have the user click in the Flash movie Add a button to the first frame of the movie that the user must click in order to continue (an "Enter", "Start" or "Login" button, for example). Any subsequent key presses can be detected by Flash.
* Use JavaScript to give focus to Flash The JavaScript focus() method can automatically give focus to the Flash movie when the HTML page containing it loads.

Note: This method only works on Windows versions of Internet Explorer.
If you see the note, using JavaScript to give focus to Flash only works in IE. For other browsers, use the first solution.

Reply
Reply
Not the answer you were looking for? Post your question . . .
178,103 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Javascript / DHTML / Ajax Forum Contributors