Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set focus to iframe body/content in firefox?

i have an ifram, which has hidden visibility. i click on button - iframe will be visible and i want to focus on its body/content. because now i must click on button and then into iframe, so thats two clicks. i want to do it on one click, but dont know how to focus in firefox.

in explorer it is ok:

var iframe_window = window.frames["myFrame"];
iframe_window.document.body.focus();

try lot of examples for firefox, but they dont work. anybody know how to do it in firefox ? thanks.

like image 445
mm. Avatar asked Oct 02 '09 08:10

mm.


People also ask

Can you focus in an iframe?

If you're trying to set focus to an element in an iframe that has already been loaded, you need to set focus to the iframe first, then to the element. myField. focus();

How do I enable iframe in firefox?

You can change this behaviour in your own Firefox installation by typing about:config in the address bar and setting security. mixed_content. block_active_content to false .

How do I use iframe tags?

Definition and UsageThe <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document. Tip: Use CSS to style the <iframe> (see example below). Tip: It is a good practice to always include a title attribute for the <iframe> .


1 Answers

Try to set the focus to iframe_window first and to your actual content next:

iframe_window.focus();
iframe_window.contentDocument.body.focus();
like image 72
Carsten Beck Avatar answered Oct 06 '22 22:10

Carsten Beck