Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a hyperlink on the same page with javascript?

Tags:

javascript

I am using this to open on a new window:

<div class="backbutton" OnClick="javascript: window.open('http://www.goesback.com')">Go back</div>

How to amend this if I want onclick to open a hyperlink on the same page?

thanks.

like image 600
user1065673 Avatar asked Jan 19 '26 00:01

user1065673


1 Answers

You just set the url to the window.location.href

so

<div class="backbutton" OnClick="window.location.href = 'http://www.goesback.com'">Go back</div>

But you should really just convert it to a regular link

<a class="backbutton" href="http://www.goesback.com">Go back</div>
like image 54
Gabriele Petrioli Avatar answered Jan 21 '26 13:01

Gabriele Petrioli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!