0

So, here's the picture: page1 has, at the bottom of it, a frame loading page2. The question is: can use a javascript (how?) in page2, so when the page1 loads, it will focus to the frame loading page2?
Thanks!

3
Contributors
14
Replies
15
Views
6 Years
Discussion Span
Last Post by twiss
0

Frames don't have a focus. What exactly do you want to do? Also, do you really need a frame? Avoid them :)

0

I need them :)
All I want is above, maybe I can explain again using different words.. I want that when I load page1, it will focus on the page2 which is loaded by a frame at the bottom of page1. Also, I don't want to touch page1 in any way, I need this ONLY if the page2 can do this trick.
So again, page1 loads and focus on the frame containing page2, which (page2) contains the javascript (or else) to trigger the focus to happen - what is that script?
Thanks!

0

You can make an input field in the frame have focus:

document.getElementById('fieldid').focus()
0

You can make an input field in the frame have focus:

document.getElementById('fieldid').focus()

Can you be more explicit, please? Or better, provide the exact code I must use inside page2?
Thanks!

...a little later I got it. This does what I want:

<html>
<body onload="setFocus();">
<script language="JavaScript">
      function setFocus() {
            document.getElementById('link').focus();
           document.getElementById('link').value='xxx';
      }
</script>
<a id="link" href="http://xxx">xxx</a>
</body>
</html>

Thanks for the indications.

Edited by wattaman: got it

0

Nope, was wrong, it works partially ... only in IExplorer, not in Firefox, Chrome or Opera.

0

Change document to frame.contentWindow.document, where frame is the frame your element is in.

0

Doesn't work.
Changing that makes it not to work, not even in IE.

0

Sorry, didn't read carefully enough. You have to move your script to the head:

<html>
<head>
<script>
window.onload = function() {
  document.getElementById('link').focus();
};
</script>
</head>
<body>
<a id="link" href="http://xxx">xxx</a>
</body>
</html>

Edit: no, that's probably not what you mean. What was the goal of your .value change? Perhaps you mean innerHTML? Or href?

Edited by twiss: n/a

0

What was the goal of your .value change? Perhaps you mean innerHTML? Or href?

... sorry, I have no idea what are you talking about - my goal is what I wrote in the first post/thread :) ... just don't know how to accomplish this.

0

- Does it work if you do what I posted above?
- If not, what was the goal of document.getElementById('link').value='xxx'; ?

0

if document in frame2 is supposed to gain focus, why not <body onload='self.focus();'> in the document that is loading in frame 2

in frame1 <body onload='parent.frame2.focus();'>

Edited by almostbob: n/a

0

Does that have any real meaning at all (for frames)? My guess was that an input needed focus.

0

Does that have any real meaning at all (for frames)? My guess was that an input needed focus.

you can apply focus to any element,
for this usage, focus is transferred to the body element within the frame, which of course fails(as expected) in any real sennse, leaving the frame in focus. <<--- what happens when you 'hmmm'' when trying to gather your thoughts and voice recognition is turned on
focus on an input item allows data entry, because the element is capable of entry
focus on an element that can do nothing, does nothing

Edited by almostbob: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.