Hyper links are used to link different pages within a site and outside a site to each other. Same thing can be achieved by using a button. We can use a button to link different pages. We will connect the url of the new page to the onclick event of the button. We can do this by using a form and a submit button but there is no point in using a form for a hyper linking of pages. So here are some examples of using buttons to link different pages.
<input type="button" onClick="parent.location='index.html'"
value="click here">
<input type="button" onClick="location.href='index.html'"
value="click here">
<input type="button" onClick="location.href='../'"
value="click here to visit home page">
<input type="button" onClick="
parent.location='https://www.plus2net.com/'"
value="click here to visit home page">
<a href="../"><input type="button" value="HOME"></a>
Some time from SEO angle linking using a button is not a good idea as we loose the anchored text advantage of hyper linking. Read the article on search engine friendly page design to know more on this.
onClick=parent.open()
<input type="button" onClick="parent.open('https://www.plus2net.com/')"
value="click here to visit home page">
<input type="button"
onClick="window.open('button-child.php','demo','width=550,height=300,left=150,top=200,toolbar=0,status=0');"
value="Open child Window">
Source code of the buttons used in Child window is here
<input type="button"
onClick="opener.location='https://www.plus2net.com/'"
value="Make the Main window change">
<input type="button"
onClick="opener.location='https://www.plus2net.com/html_tutorial/button-linking.php'"
value="Bring the button linking tutorial again">
<input type="button"
onClick="location='https://www.plus2net.com/'"
value="Make the current window change">
<input type="button"
onClick="self.close();"
value="Close this window">
<a href="../">
<img src="../images/top2.jpg">
</a>
target=new. This can be used in text links and buttons also.
<a href="../" target="new">
<img src="../images/top2.jpg">
</a>
Add a JavaScript alert before opening the link:
<button onclick="confirmRedirect()"> Go to Example </button>
<script>
function confirmRedirect() {
if (confirm("Do you want to visit the page?")) {
window.location.href = "https://www.example.com";
}
}
</script>
| rozel rosauro | 22-03-2012 |
| it is very helpful to me ...thanks | |
| N G Sundar | 14-05-2012 |
| Exactly what I wanted. Did not want to submit the form; instead wanted to go to another page. | |
| rozel rosauro | 05-06-2012 |
| it is very helpful to me ...thanks | |
| chavda bhavna | 07-08-2012 |
| nice understanding exampels.good.thanks. | |
| DekeR | 19-09-2012 |
| very helpfull - just ask google, and dont need read API or something like that, THX | |
| harini | 26-12-2012 |
| Amazing article.. thanks for the help. | |
| sanju | 07-01-2013 |
| how i can open a folder from pc by clicking button and change photo by selecting any photo | |
| venkat | 15-03-2013 |
| very useful .... | |
| Vengefull | 16-07-2013 |
| Good article, very helpfull. Thank you. | |
| anis | 19-04-2014 |
| what is the different between location and parent.location | |
| lyn | 27-05-2014 |
| Its really helpful :,) tq so much | |
| wiki | 10-07-2014 |
| Thanks you sooo much,,, this is what i'm looking for... | |
| makbul | 28-09-2014 |
| i want to generate click evant on a .cs with use of html button | |
| JohnC | 09-10-2014 |
| Thank you all. This has enabled me to get our local site running. Do you have a book available for purchase or download? Once more thank you so very much. | |
| rasool | 30-04-2015 |
| Tnx A Lotttttt ! Best Site Ever :) | |
| Ken | 09-06-2015 |
| Thank you so much!!! | |
| Ishman | 08-10-2015 |
| How do i pass parameter while redirecting to other page using onClick function | |
| KyleInMC | 16-10-2015 |
| Um... the open.window onClick thing doesn't work in the Google Sites editor. It says "Missing or malformed url parameter" what do I do? | |
| Bramhananda reddy | 28-02-2016 |
| Apart from other stuff Your Explanation in practical is really very nice.Keep it up and wish u all the best | |
| Hasini Silva | 03-07-2016 |
| This is amazing. Thanks a lot! | |
| manik | 03-11-2017 |
| thanks for this i had been looking for this from a long time and found it here | |
| ibexy | 20-05-2018 |
| can this be used with image links? | |
| smo1234 | 10-08-2018 |
| To take the parameter to different page or different site , you can use query string. | |
| smo1234 | 10-08-2018 |
| One image ( plus2net logo ) is added as a link to home page. | |