iframe focus

C

carlos

What I would like to do is set the focus on the first childNode
element of my iframe src page. I can't assume I know any of the id's
or content inside the iframe src. Therefore, what I would like to do
is walk the contents of the innerHTML, and when I come across an
input, image, button or any nodeType that can have focus, set the
focus, and stop tracersing the innerHTML. I started putting something
together, but it isn't working.. here is what I have so far.. Any of
you experts have any advice?

function setInnerFrameFocus(frameID) {

var frame
=document.getElementById(frameID.name).contentWindow.document;

var focusElements =
frame.documentElement.lastChild.childNodes;

for(n=0;n<focusElements.length;n++){ // walk through all
the focus element child nodes
for(i=0;i<focusElements[n].childNodes.length;i++){ check
the childnodes children for focus elements
//stop if a focus element is found

if((focusElements[n].childNodes.nodeName=="IMG") ||
(focusElements[n].childNodes.nodeName=="A") ||
focusElements[n].childNodes.nodeName=="INPUT") ){
//set the focus - not working though??
focusElements[n].childNodes.focus();
i=focusElements[n].childNodes.length;
}//end if
}
}
}
 
C

carlos

carlos said the following on 2/7/2008 4:32 PM:


Best advice? Give up now and save yourself a lot of headaches. You can't
reliably tell whether an element (especially form elements) can gain
focus or not.

<URL:http://groups.google.com/group/comp.lang.javascript/browse_thread/thr....>
<URL:http://groups.google.com/group/comp.lang.javascript/browse_thread/thr....>

Ignore Thomas' failed attempt at detecting focus unless you are looking
for examples of failed scripts.

The two threads explain some of the many problems with trying to
determine whether you can actually set focus to an element or not.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -http://jibbering.com/faq/index.html
Javascript Best Practices -http://www.JavascriptToolbox.com/bestpractices/

Randy.. thanks for the info.. You already saved me from a big headache
by showing me those posts.. Thanks..
 

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

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top