JavaScript load a page on button click JavaScript load a page on button click javascript javascript

JavaScript load a page on button click


Simple code to redirect page

<!-- html button designing and calling the event in javascript --><input id="btntest" type="button" value="Check"        onclick="window.location.href = 'http://www.google.com'" />


Don't abuse form elements where <a> elements will suffice.

<style>    /* or put this in your stylesheet */    .button {        display: inline-block;        padding: 3px 5px;        border: 1px solid #000;        background: #eee;    }</style><!-- instead of abusing a button or input element --><a href="url" class="button">text</a>


Just window.location = "http://wherever.you.wanna.go.com/", or, for local links, window.location = "my_relative_link.html".

You can try it by typing it into your address bar as well, e.g. javascript: window.location = "http://www.google.com/".

Also note that the protocol part of the URL (http://) is not optional for absolute links; omitting it will make javascript assume a relative link.