Home » Javascript

JavaScript - Function to Refresh Page on Button Click

In this example, we will learn how to refresh current webpage on button click event. Here we are creating a JavaScript function that will refresh webpage on Button Click event.

location.reload(); is used to refresh the page, we will call this method within the JavaScript function with confirmation box.

JavaScript Code Snippet - Refresh Webpage on Button Click

JavaScript function

<script type="text/javascript">
	function refreshPage(){
		if(confirm("Are you sure, want to refresh?")){
			location.reload();
		}				
	}
</script>

HTML Source Code with JavaScript

<!--JavaScript - Function to Refresh Page on Button Click.-->
<html>
	<head>
		<title>JavaScript - Function to Refresh Page on Button Click.</title>
		<script type="text/javascript">
			function refreshPage(){
				if(confirm("Are you sure, want to refresh?")){
					location.reload();
				}				
			}
		</script>
	</head>

	<body style="text-align: center;">
		<h1>JavaScript - Function to Refresh Page on Button Click.</h1>
		<p><input type="button" value="Refresh Webpage." onclick='refreshPage()'/>
	</body>

</html>

Result

refresh page on button click




Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.