Giving Focus to the contents of an IFrame

M

Mike

I have an intranet page which has an iframe which links to a number of
different possible .NET pages.

In one of the embedded .NET pages (and soon to be others) we want to be

able to capture keystrokes in order to link to other apps. we do this
by setting document.onkeydown to a function which handles the various
possibilities.


The problem I have is that when the intranet page loads with my .NET
page in its iframe, focus is not given to the .NET page, and so in
order for the page to capture keystrokes you have to click on the
contents of the iframe, which is both clunky and (it seems to me)
unnecessary.


How do I automatically give focus to the contents of the iframe when it

loads up? I've tried putting the following script at the bottom of the
intranet page itself, but this doesn't seem to work:


<script
language='javascript'>document.getElementById("contentarea").focus();</scri­pt>



("contentarea" is the name of the iframe which contains the .NET app).


Can anyone tell me what I'm doing wrong?


Thanks for any help you can give..


Mike.
 
M

marss

Mike said:
<script
language='javascript'>document.getElementById("contentarea").focus();</scri­pt>



("contentarea" is the name of the iframe which contains the .NET app).

In order to get element by id you need set id="contentarea" but not
name="contentarea".



If it is a simple typo during the posting then try following code (it
works both IE6 and Firefox):
var fr = document.getElementById("contentarea");
if (document.all) //IE
fr.document.body.focus();
else //Firefox
fr.contentDocument.body.focus();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top