0

I want to get redirect by click on button, I use:

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

and it workf if is clicked on page http://ADDRESS but if is clicked when url is like http://ADDRESS/something it redirects to http://ADDRESS/something/first

How is it possible to get redirect just before ADDRESS but not put this value (ADDRESS) because it could change? (for this example it should get http://ADRESS/first insted of http://ADDRESS/something/first)

karl person
  • 263
  • 1
  • 9

1 Answers1

1

You want /first not first.

Without a slash, it's a relative link. With the slash, it's absolute to the base URL.

<input type="submit" onclick="location.href='/first'" value="goSomewhere1"/>
<input type="submit" onclick="location.href='/second'" value="goSomewhere2"/>
Matt Fletcher
  • 8,182
  • 8
  • 41
  • 60