Get the full URI from the href property of a link

后端 未结 4 558
粉色の甜心
粉色の甜心 2020-12-13 14:07

I would like to have a confirmation on some point.

My goal is to always get the same string (which is the URI in my case) while reading the href property from a link

4条回答
  •  庸人自扰
    2020-12-13 14:37

    YES, you can rely!

    Once when people was using simple javascript (no jQuery) many asked the opposite of what you are asking, they wanted to get the real url as written in the href attribute and not the full one, in such case they used to simply do:

    my_a_dom_node.getAttribute('href', 2); //works both IE/FF
    

    Then it came jQuery that helped people not to waste their time in finding out they would need such code and jQuery always returns the real url as written in the href attribute.

    It's funny that now someone is asking how to get the full url because jQuery returns the one written in the href attribute.

提交回复
热议问题