href link to # question

早过忘川 提交于 2019-12-13 06:43:40

问题


I have a question about the href link, tried googling it but could not find much info on this. I have a href link like this:

<a href='#' onclick='openSerialWindow();return false;'><h:outputText value="#{i18n.regFindSerialNumber}" /></a>

previously the # was replaced by the page.htm that it should link to and that caused an error when user right clicked on the link and chose 'Open in new window/tab'. After replacing the page.htm with # it works fine user can even r/c and open it in new tab/window.

If user simply clicked on the link both ways above worked (the # and page.htm), so I am wondering what is the true meaning of #?

thanks.


回答1:


# is an anchor hash and points to the top of the current page.

You can create anchors in your document like this: <a name='anchor'></a> and then jump to them by adding #anchor to the page's URL. The browser will jump to the position without reloading.

If linking to page.htm produced an error, then page.htm is an incorrect link.

The href attribute is there only as fallback in case there is no Javascript. Javascripts's return false; prevents execution of the link. Linking to # means that if javascript is turned off, nothing will happen by clicking on the link except that the browser will jump to the top of the page.




回答2:


See: http://www.w3.org/TR/html4/struct/links.html

A # indicates a link to a [named] anchor within a page.

An <A> which invokes some javascript generally doesn't work with the "open in new window/tab" command.



来源:https://stackoverflow.com/questions/1971455/href-link-to-question

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