Reputation: 57974
I need to basically add this to my page:
<body onload="document.getElementById('WeddingBandBuilder').focus()">
However due to my template I cannot change the tag. So is there a way to do the equivalent with a script in the < head > tag or something?
Thanks!
Upvotes: 3
Views: 4195
Reputation: 5917
I might check if that page has already included jQuery? If so, you can do something like this:
$(document).ready(function() {
$('#WeddingBandBuilder').focus();
});
Upvotes: -2
Reputation: 25931
You should always be careful there isn't already a window.onload
defined. I've been burned a number of times by assuming I would be the only one attaching things to <body onload="...">
or window.onload
.
See this answer and comments for a solution to this issue.
Upvotes: 0
Reputation: 38966
<script>
window.onload = function() {document.getElementById('WeddingBandBuilder').focus()};
</script>
Upvotes: 8
Reputation: 10420
Use a JS library like jQuery or Prototype and create an external script file with something like this:
for jQuery:
$(function() { $('#WeddingBandBuilder').focus(); });
for Prototype:
Event.observe(window, 'load', function() { $('WeddingBandBuilder').focus(); });
Upvotes: -1