getting focus to document element on load | | |
I'm trying to get an <a> element to gain the focus onload, but only get
back 'has no properties'.
Reading through this ng, its clear that unless the element is within a
form, this doesn't happen, but according to the w3 TR on html 4.01, the a
element can take onFocus commands, which to me means you can do
document.getElementById(element).focus() ?
I'm trying to get the focus to a specific paragraph, so the page scrolls to
it on loading, but as the page in question is dynamic, i can't feed the #
van the URL | | | | re: getting focus to document element on load
s_m_b wrote:[color=blue]
> I'm trying to get an <a> element to gain the focus onload, but only get
> back 'has no properties'.
> Reading through this ng, its clear that unless the element is within a
> form, this doesn't happen, but according to the w3 TR on html 4.01, the a
> element can take onFocus commands, which to me means you can do
> document.getElementById(element).focus() ?[/color]
<a> elements have onfocus intrinsic events, which means you can make
things happen when they gain focus, usually by tabbing to or clicking
on them. It does not mean the element has a focus() method.
[color=blue]
>
> I'm trying to get the focus to a specific paragraph, so the page scrolls to
> it on loading, but as the page in question is dynamic, i can't feed the #
> van the URL[/color]
That is what anchors are for. Giving the <a> focus will not
necessarily scroll the page to it, but using it as an anchor will if
there is sufficient depth in the page.
<URL:http://www.w3.org/TR/html401/struct/links.html#h-12.1>
--
Rob | | | | re: getting focus to document element on load
RobG <rgqld@iinet.net.auau> wrote in
news:425bad55$0$20404$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
[color=blue]
> s_m_b wrote:[color=green]
>> I'm trying to get an <a> element to gain the focus onload, but only
>> get back 'has no properties'.
>> Reading through this ng, its clear that unless the element is within
>> a form, this doesn't happen, but according to the w3 TR on html 4.01,
>> the a element can take onFocus commands, which to me means you can do
>> document.getElementById(element).focus() ?[/color]
>
> <a> elements have onfocus intrinsic events, which means you can make
> things happen when they gain focus, usually by tabbing to or
> clicking on them. It does not mean the element has a focus()
> method.[/color]
ah - that explains it.
[color=blue]
>[color=green]
>>
>> I'm trying to get the focus to a specific paragraph, so the page
>> scrolls to it on loading, but as the page in question is dynamic, i
>> can't feed the # van the URL[/color]
>
> That is what anchors are for. Giving the <a> focus will not
> necessarily scroll the page to it, but using it as an anchor will if
> there is sufficient depth in the page.
>
> <URL:http://www.w3.org/TR/html401/struct/links.html#h-12.1>
>[/color]
yes, that I know, but if you add '?x=y' into the URL it doesn't work any
more. You either get the contents of the GET ignored or the anchor
reference is. | | | | re: getting focus to document element on load
I'm having a similar situation with normal text links. For example,
after closing an iframe or hiding a division I want focus to go to a
certain text link. I tried:
document.links[2].focus;
to target the 3rd link on the page after the closing or hide, and it
doesn't work. Is this possible ?
Later, Art. | | | | re: getting focus to document element on load
In my previous post I forgot to point out that the:
document.links[2].focus;
is not part of a function. It's a stand alone statement within the
script tags. Might that be the problem ? | | | | re: getting focus to document element on load
s_m_b wrote:[color=blue]
> RobG <rgqld@iinet.net.auau> wrote in
> news:425bad55$0$20404$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
>
>[color=green]
>>s_m_b wrote:
>>[color=darkred]
>>>I'm trying to get an <a> element to gain the focus onload, but only
>>>get back 'has no properties'.
>>>Reading through this ng, its clear that unless the element is within
>>>a form, this doesn't happen, but according to the w3 TR on html 4.01,
>>>the a element can take onFocus commands, which to me means you can do
>>>document.getElementById(element).focus() ?[/color]
>>
>> <a> elements have onfocus intrinsic events, which means you can make
>> things happen when they gain focus, usually by tabbing to or
>> clicking on them. It does not mean the element has a focus()
>> method.[/color]
>
>
> ah - that explains it.
>
>[color=green][color=darkred]
>>>I'm trying to get the focus to a specific paragraph, so the page
>>>scrolls to it on loading, but as the page in question is dynamic, i
>>>can't feed the # van the URL[/color]
>>
>> That is what anchors are for. Giving the <a> focus will not
>> necessarily scroll the page to it, but using it as an anchor will if
>> there is sufficient depth in the page.
>>
>> <URL:http://www.w3.org/TR/html401/struct/links.html#h-12.1>
>>[/color]
>
> yes, that I know, but if you add '?x=y' into the URL it doesn't work any
> more. You either get the contents of the GET ignored or the anchor
> reference is.[/color]
I think you need to explain a bit more about what you are trying to
do - do you have bit of code showing what you are up to?
--
Rob | | | | re: getting focus to document element on load
Art X wrote:[color=blue]
> I'm having a similar situation with normal text links. For example,
> after closing an iframe or hiding a division I want focus to go to a
> certain text link. I tried:
>
> document.links[2].focus;
>
> to target the 3rd link on the page after the closing or hide, and it
> doesn't work. Is this possible ?
>
> Later, Art.
>[/color]
Give the a element a name, that makes it an anchor. Fire some event
and set the page location to <currentURL> + '#' + <anchorName>.
That will navigate to the link and put it in focus:
<a href="#freddy">freddy</a>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><b r><br><br>
<a name="freddy" href="http://www.apple.com" onfocus="
alert('Hey, ' + this.name + ' got focus');">Apple</a>
--
Rob | | | | re: getting focus to document element on load
Art X wrote:[color=blue]
> In my previous post I forgot to point out that the:
>
> document.links[2].focus;
>
> is not part of a function. It's a stand alone statement within the
> script tags. Might that be the problem ?
>[/color]
I ignored it. If you were trying to call the focus method, then:
document.links[2].focus();
will do the trick, but using an anchor will work without JavaScript.
Probably should test the method before trying to use it:
if (document.links[2].focus) document.links[2].focus();
--
Rob | | | | re: getting focus to document element on load
Thanks Rob,
I'll try the anchor.
Later, Art. | | | | re: getting focus to document element on load
RobG <rgqld@iinet.net.auau> wrote in
news:425bd215$0$20416$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
[color=blue]
> s_m_b wrote:[color=green]
>> RobG <rgqld@iinet.net.auau> wrote in
>> news:425bad55$0$20404$5a62ac22@per-qv1-newsreader-01.iinet.net.au:
>>
>>[color=darkred]
>>>s_m_b wrote:
>>>
>>>>I'm trying to get an <a> element to gain the focus onload, but only
>>>>get back 'has no properties'.
>>>>Reading through this ng, its clear that unless the element is within
>>>>a form, this doesn't happen, but according to the w3 TR on html
>>>>4.01, the a element can take onFocus commands, which to me means you
>>>>can do document.getElementById(element).focus() ?
>>>
>>> <a> elements have onfocus intrinsic events, which means you can
>>> make things happen when they gain focus, usually by tabbing to or
>>> clicking on them. It does not mean the element has a focus()
>>> method.[/color]
>>
>>
>> ah - that explains it.
>>
>>[color=darkred]
>>>>I'm trying to get the focus to a specific paragraph, so the page
>>>>scrolls to it on loading, but as the page in question is dynamic, i
>>>>can't feed the # van the URL
>>>
>>> That is what anchors are for. Giving the <a> focus will not
>>> necessarily scroll the page to it, but using it as an anchor will
>>> if there is sufficient depth in the page.
>>>
>>> <URL:http://www.w3.org/TR/html401/struct/links.html#h-12.1>
>>>[/color]
>>
>> yes, that I know, but if you add '?x=y' into the URL it doesn't work
>> any more. You either get the contents of the GET ignored or the
>> anchor reference is.[/color]
>
> I think you need to explain a bit more about what you are trying to
> do - do you have bit of code showing what you are up to?
>[/color]
ah..............
I've just been through the code in a little more depth to check it, and
found the problem - the anchor I was sending is missing on the target
document. Another anchor that I've just tried, does exist and works.
I'll have to find where this duff one comes from now [blush] |  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|