Welcome to WebmasterWorld Guest from 54.196.214.35

Forum Moderators: open

Message Too Old, No Replies

Change page focus

     
2:03 pm on Apr 10, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 12, 2004
posts:789
votes: 0


Just a quickie, is it possible to write some javascript (in a simple <script> ... </script>) that changes the browser's focus to a certain id?
7:42 pm on Apr 10, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 12, 2005
posts:371
votes: 0


ahmedtheking,

Yes, you can do something like this:

<script>
document.getElementById('someID').focus();
</script>

Usually you want to do it in the body tag in the onLoad event, ala:

<body onload="document.getElementById('someID').focus();">

Chad

7:23 am on Apr 11, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 12, 2004
posts:789
votes: 0


Awesome!
9:20 pm on Apr 15, 2006 (gmt 0)

New User

5+ Year Member

joined:Apr 11, 2006
posts:5
votes: 0


hi, if you open a popup through a link can you set the focus to the link rather than have the browser jump to the top of the page this happens with

<a href="" onclick="openpop(features)"></a>
or"#"
Cheers

11:44 am on Apr 16, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 12, 2004
posts:789
votes: 0


Yeah, I know that much, just wanted to know how to make it automatic without having to add to the <body> tag.

gph

2:42 pm on Apr 16, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Jan 31, 2002
posts:285
votes: 0


just wanted to know how to make it automatic without having to add to the <body> tag.

window.onload=function(){
...
}

or

window.onload=myFunction;

8:19 pm on Apr 16, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 12, 2004
posts:789
votes: 0


Ok, i'll try all these methods out, thank you!