tag:blogger.com,1999:blog-34454975.post7224463369853662518..comments2023-06-28T16:58:41.189+02:00Comments on Web Reflection: input.focus() ... something really annoying!Andrea Giammarchihttp://www.blogger.com/profile/16277820774810688474noreply@blogger.comBlogger9125tag:blogger.com,1999:blog-34454975.post-68463604805316947292009-06-07T18:54:38.893+02:002009-06-07T18:54:38.893+02:00... ehr ... yes, and that's why I've alrea...... ehr ... yes, and that's why I've already posted the cross-browser unobtrusive code ...Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-89091138755727995972009-06-07T17:19:49.713+02:002009-06-07T17:19:49.713+02:00I catch your point, now. You're right, someth...I catch your point, now. You're right, something must be done if the input is not the first on the page.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34454975.post-34776046360414458762009-06-06T21:06:44.189+02:002009-06-06T21:06:44.189+02:00it's gonna be for my children, if any :D ... j...it's gonna be for my children, if any :D ... jokes a part, HTML 5 autofocus is OK, I simply provided quick and cross-browser alternatives. Unfortunately, both Google guys, msn, my bank, or whoever mentioned developer will never implement this trick :(Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-63625317870867336132009-06-06T20:30:55.132+02:002009-06-06T20:30:55.132+02:00How about the autofocus attribute?How about the <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/forms.html#autofocusing-a-form-control" rel="nofollow">autofocus attribute</a>?Krijn Hoetmerhttp://krijnhoetmer.nl/noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-64028773248824863312009-06-06T17:21:53.217+02:002009-06-06T17:21:53.217+02:00iframe was about this post, as example, but you ar...iframe was about this post, as example, but you are still not considering that as tabindex attribute exists because the order of the fields is not necessary related to fields importance, your script could run after the main input while I was writing something else in an input before. Let's say a age with a login and a search, the search has your script, login comes before and I am using it, or vice-versa, so still your solution is obtrusive, mine is user-action oriented, not developer oriented. Better? :)Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-16605285215119883112009-06-06T17:17:01.665+02:002009-06-06T17:17:01.665+02:00My point was that the focussing script would run b...My point was that the focussing script would run before any more of the page loaded. No deferred onload script necessary. The Adwords iframe wouldn't have a chance to load before the focussing occurred.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-34454975.post-7259809735793129822009-06-06T16:41:39.555+02:002009-06-06T16:41:39.555+02:00P.S. scenarios are a lot, the most common is the c...P.S. scenarios are a lot, the most common is the classic google adsense at the end of the page with an iframe plus images, etc etc ... if this is after the input when my page is loaded I could have written already main input so why the script which aim should be help me makes things more complicated removing my focus? ... hope you got my point.Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-68542858343423134112009-06-06T16:38:49.430+02:002009-06-06T16:38:49.430+02:00while1dan, I would use <noscript> tag with t...while1dan, I would use <noscript> tag with the input, and a document write('... input ...') plus focus for W3 and WAI compatibility but still, this is not a "universal" solution because if for some reason I already put focus in another field, I do not get why in 2009 I should still loose that focus, my choices, before the page is totally loaded. Not flexible, focus has to be set <b>only</b> if not set already by user actions. That's my point of view.Andrea Giammarchihttps://www.blogger.com/profile/16277820774810688474noreply@blogger.comtag:blogger.com,1999:blog-34454975.post-51254541744314710802009-06-06T16:21:56.720+02:002009-06-06T16:21:56.720+02:00Setting focus on page load is wrong. A good brows...Setting focus on page load is wrong. A good browser should allow you to jump into the first field using a single tab (and tabindex is still an HTML attribute right?). If you don't use keyboards for navigation, or don't know how, then clearly you don't mind using your mouse.<br /><br />However, if you are forced to do it because some boss instructed you to (or whatever), what's wrong with:<br /><br /><input id="my_input" /><br /><script type="text/javascript"><br /> document.getElementById("my_input").focus();<br /></script><br /><br />This should load immediately after the input tag loads on most browsers and only screw up on the very slowest of connections. Right?Anonymousnoreply@blogger.com