Empty HTML href leads to directory listing in IE

大憨熊 提交于 2019-12-01 18:04:28

问题


I have a website with separate HTML files (actually .shtml, but this is unimportant for this issue). These shtml files contain a picture, and a forward- and backbutton so I can switch back to the preview shtml file or browse to the next one, like in a gallery. All these shtml files are generated locally. I wrote some kind of generator in Java. Basically this works, the first shtml file and the last points to <a href=""....>. When the users clicks on it, nothing happens. This is the expected behaviour. It was tested in FF, Chrome, Opera and it works there, but not in IE. When I click back or next in IE, I get the directory listing. Is this an IE problem or just a configuration issue? Probably I have to change the generator code but I don't want to if I don't have to. So is there another solution for that?


回答1:


From http://msdn.microsoft.com/en-us/library/cc848861%28v=vs.85%29.aspx

If HREF is specified as a blank value ( href="" or href=), executing the link might display the directory containing the current document , or it might generate an error, depending on other elements in the document and the server environment.

This behaviour is by design and there is no work around. You'll have to come up with something that doesn't use a blank href value, such as href="#"




回答2:


Change it to <a href="#"> or <a href="javascript:;">



来源:https://stackoverflow.com/questions/7966791/empty-html-href-leads-to-directory-listing-in-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!