postnote

We are currently looking for Ruby on Rails contractors to join our Wellington based team. The initial contract would be 6 months and in that time you would be a part of an awesome team who are passionate about what they do

News & Updates

URL Anchors conflict with JavaScript focus routines

by nigelramsay.

I have been using some simple JavaScript to focus and select the contents of an form input box when a page first loads. But, was finding that it only works intermittently.

h3. Websphere Portal

To add some context, we're using Websphere Portal - and it has some unique behavior. When you load a page that has a portlet embedded in it, it adds a hidden anchor near the top of the portlet. The portal-generated URL to the page includes an anchor to the portlet that generated the "render event".

The standard behavior is that the browser jumps to the position of the referenced anchor when the page has finished loading.

But, if you have an inline JavaScript command to set focus to a field, it will only have focus for the small period of time. This is between the JavaScript commands running, and when the page finishes loading. Note: this is the behavior in Firefox.

h3. Solutions

There are two options for resolving this issue:

# Disable the use of anchors; or # Connect your initialisation/focusing routines to the "onload" event

Twitter