简体   繁体   中英

Html anchors not working correctly in IE9

I have this dirty html that is currently used in my company, the issue is that the hyperlinks or anchors work in IE8, but not in IE9 any reason why this is not working in IE9?. Basically its just clicking on the link and then it should focus on the id, like when i click on specialties I see the url changing like this

file:///C:/Users/TestUser/Desktop/test.html#c3

Now in IE8 when i do the click it correctly goes to that section #c3

Well this code does not work either in IE9

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<p id="titleC"><a href="#c3">Specialty</a></p>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<p id="#c3">Did it work?</p>
<p>Then your code is wrong</p>
</body>

Thehash is the problem:

<p id="c3">Did it work?</p>

(without the hash) should work.

Maybe you should use

<a id="c3" name="c3">Did it work?</a>

for compatibility reasons.

All you attributes need to but surrounded by single or double quotation marks. For one on the many incorrect lines in the html

<P id=#titleQ class=style1>

Should be

<P id="#titleQ" class="style1">

Run into the same issue and from my experience, on IE9 the anchor tag <a> does not recognise id or name on other elements other than another <a> tag, so as a workaround, you probably want to add a dummy empty <a> tag link above the element you want to link to, like so:

<body>
    <p id="titleC"><a href="#c3">Specialty</a></p>
    ...
    <a id="c3" name="c3"></a>
    <p>Did it work?</p>
    <p>Then your code is wrong</p>
</body>

尝试添加此元标记,也许可以解决该问题:

<meta http-equiv="X-UA-Compatible" value="IE=8">

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