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


Input tag

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

onclick location href Example

HTML code:


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




Button html href

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

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

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