简体   繁体   中英

focus() in IE6 issues

I seem to have a problem some people already have, but I don't manage to fix it.

I have a Javascript function that puts the focus on a particular field in my all-generated webpage (ASP.NET 2.0). This javascript function is registered via a ScriptManager object, at the end of my page.

When I enter the page for the first time, the focus() doesn't work. I can see that I call it correctly, but the focus doesn't set in the specified control (found with getElementById ). On this page I have a button that just links to the same page, and when I click on it and the page is refreshed, the focus is ok.

I really don't understand, I've tried many proposed solutions ( settimeout , defer , ...), I can't manage to make it work.

It works fine on IE8, but not all my users have it.

Can anyone help me please ?

Are you using innerHTML to load AJAX content? If so STOP THAT! NEVER use innerHTML or adjacentHTML, stick to W3C DOM compliant methods (importNode, insertBefore and appendChild) otherwise content will be dumped on the DOM and not correctly processed. This is one of the many quiet bugs that really comes down to input from others.

Also make sure you're not using really simple terms that are considered reserved. Microsoft has a list somewhere (official or not) of words that if you use that IE simply won't say anything and will just not execute the code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM