简体   繁体   中英

Redirect to Url after domain

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 )

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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM