Skip to content

onclick location href | Open HTML pages/website on a button click

If you want to open these HTML pages on a button click use onclick location href.

onclick Attribute

onclick="window.location.href='Students.html';"

Input tag

<input type="button" onclick="location.href='https://google.com';" value="Go to Google" />

onclick location href Example

HTML code:

<html>
<body>

	<input type=button onClick="location.href='index.html'" value='click here'>
	
</body>

</html>

Output:

OR

Button html href

<!-- if you are on Window : --> 
<button onclick="window.location.href='page2.html'">
  Button
</button>

<!-- if you are on linux or macOS : -->
<button onclick="location.href='page2.html'">
  Button
</button>

Do comment if you have any doubts and suggestions on this HTML/JS tutoiral.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

3 thoughts on “onclick location href | Open HTML pages/website on a button click”

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading