域后重定向到Url

时间:2017-12-09 19:31:35

标签: javascript jquery html

我希望通过点击按钮获得重定向,我使用:

<inputtype="submit" onclick="location.href='first';" value="goSomewhere1"/>
<inputtype="submit" onclick="location.href='second';" value="goSomewhere2"/>

如果在页面http://ADDRESS上点击它就会工作,但如果在urlhttp://ADDRESS/something类似时点击它,则会重定向到http://ADDRESS/something/first

如何才能在ADDRESS之前获得重定向,但不能将此值(ADDRESS)放在一起,因为它可能会发生变化? (对于此示例,它应该http://ADRESS/first} http://ADDRESS/something/first} {/ 1>}

1 个答案:

答案 0 :(得分:1)

您希望/first不是first

没有斜线,它是一个相对链接。使用斜杠,它对于基本URL是绝对的。

<input type="submit" onclick="location.href='/first'" value="goSomewhere1"/>
<input type="submit" onclick="location.href='/second'" value="goSomewhere2"/>