3

I am looking to give my iframe focus but I am not sure how to do this. I put "autofocus" in the iframe tag, but it still does not truly get focus until I click with my mouse into the video.

This is what I currently have:

<iframe autofocus width="420" height="345" src="<?php echo htmlspecialchars($output); ?>"> </iframe>

Thank you for any assistance.

user3369289
  • 115
  • 1
  • 1
  • 7
  • `autofocus` is meant for use within form elements, putting it on your iframe wouldn't really do much. – the_pete Mar 10 '14 at 20:32
  • Is there a way to have the iframe selected upon page load? – user3369289 Mar 10 '14 at 20:33
  • What do you want to do within the iframe? Why does it need to be selected? We'll need a better description of what you are trying to accomplish. – the_pete Mar 10 '14 at 20:34
  • Well I am looking to be able to start and stop the video without having to click into it first. – user3369289 Mar 10 '14 at 20:36
  • Do you just want it to autoplay after it's loaded or do you still want the user to just have to, for instance, tap the space bar to start play because the play button is already highlighted? – the_pete Mar 10 '14 at 20:43
  • I already have it autoplaying, so I would like to be able to use the spacebar without having to click into the video – user3369289 Mar 10 '14 at 20:47
  • You could look at leveraging jquerys' .focus() element. api.jquery.com/focus But you'll have to inspect the video with Firebug or something similar to file the element name of the play button or video frame. See also: http://stackoverflow.com/questions/1433742/set-focus-to-field-in-dynamically-loaded-div – the_pete Mar 10 '14 at 20:51
  • I was considering jquery for this earlier. So there is no simpler solution? – user3369289 Mar 10 '14 at 20:56
  • As far as I know, no, but this should be too hard to implement with the code from the SO link I added in my previous comment. And as always, if you run into problems you can always just post again and we'll be happy to help! – the_pete Mar 10 '14 at 20:59
  • Okay thanks! I will look closely at the link you provided and report back! – user3369289 Mar 10 '14 at 21:01
  • Okay I got it working! By simply adding an ID to the iframe and a javascript. So in the iframe I added id="playingvid" and in the javascript, window onload = function(){document.getElementById("playingvid").focus();}; And it works perfectly now! Will there be any issues doing it this way instead of jquery? – user3369289 Mar 10 '14 at 21:29

0 Answers0