Home » Javascript

JavaScript - Close Current Tab on Button Click with Confirmation

In this code snippet we will learn how to close current tab on button click event with confirmation box. Here we will implement JavaScript function to close current tab with confirmation box.

JavaScript Code Snippet - Close Current Tab with Confirmation Box

JavaScript function

<script type="text/javascript">
	function closeCurrentTab(){
		var conf=confirm("Are you sure, you want to close this tab?");
		if(conf==true){
			close();
		}
	}
</script>

HTML Source Code with JavaScript

<!--JavaScript - Close Current Tab on Button Click with Confirmation.-->
<html>
	<head>
		<title>JavaScript - Close Current Tab on Button Click with Confirmation.</title>
		<script type="text/javascript">
			function closeCurrentTab(){
				var conf=confirm("Are you sure, you want to close this tab?");
				if(conf==true){
					close();
				}
			}
		</script>
	</head>

	<body style="text-align: center;">
		<h1>JavaScript - Close Current Tab on Button Click with Confirmation. </h1>
		<p><input type="button" value="Close Tab." onclick="closeCurrentTab()"</p>

	</body>

</html>

Result

close current tab using javascript




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.