Show Alert when Visitor Leaving a Web Page

Here is how to show an alert message when a visitor leaving a web page

With this code, we can show a message or dialogue of your choice when a visitor to your website wanting to leave. In PHP, i guess this is not possible so we can use this simple JavaScript.

This piece of code can also be used between your desired functions

JavaScript Code to Show Alert When User leaving

<script type="text/javascript">
  window.onbeforeunload = confirmExit;
  function confirmExit()
  {
    return "Are you sure you want leave?";
  }
</script>

 

Related Posts

Easily Integrate Stripe Payment Gateway in PHP for Any Website

Introduction: In today’s digital world, accepting online payments securely is crucial for businesses. Stripe, a popular payment gateway, provides a reliable and user-friendly platform for processing payments….

How to build API for your Website?

Are you looking to improve the functionality of your website and enhance your users’ experience? One effective way to do this is by integrating an API, or…

How to create a Database in MYSQL using PHP

Creating a database in MySQL using PHP is a common task that many web developers need to do. A database is a collection of data that is…

HTML Redirect to Other Web Page Automatically

How to redirect to another web page with html code Redirecting a page to another page is simple, you can use the below code to do that,…

PHP Array to JavaScript Array

How to convert PHP array to JavaScript array The code below can convert your php array to JavaScript array

Fix PHP Unable to find the wrapper “https” – did you forget to enable it when you configured PHP?

Here is how to fix Unable to find the wrapper “https” problem in PHP In php development, you will encounter this error when trying to access an…

Leave a Reply

Your email address will not be published. Required fields are marked *