HTML button onclick example of jumping page, you can also go back to the previous page



HTML Button has a wide range of applications. Of course, the most common usage is to submit a form, but Button can also be used with JavaScript to make many other useful applications, such as opening a new window (window.open) or using the onclick event system Do page jump, that is, after pressing the button, it will automatically go to another web page. This article is to teach you how to make a button onclick jump page. There are two examples, namely, return to the homepage after onclick and return to the home page after onclick. Previous page.


Example 1: Suppose we want to jump to the homepage of this site, the syntax is as follows

<input type ="button" onclick="javascript:location.href='https://jasonchen050319.blogspot.com/'" 

value="Back to Jason SEO homepage"></input>


Present results



When onclick, we use JavaScript's location.href grammar to bring the webpage to the homepage of this site. You can also change the web address to other webpages. The value of the button refers to the value of the button. This can also be set by yourself.

Example 2: Back to the previous page after button onclick, the syntax is as follows

<input type ="button" onclick="history.back()" value="Back to the previous page"></input>

In the example, we use the syntax of history.back(), which means going back to the previous page of the browser record, which also means that if there is no record, there will be no response. There are many ways to return to the previous page, and we also have a detailed introduction, please see the extended reading.

Post a Comment

0 Comments