facebook twitter youtube
in JavaScripts - 08 Jan, 2011, This Tutorial Has Been Viewed 37,373 Times.
by admin - 6 comments
Alert a message before leaving a web page using javascript
VN:F [1.9.22_1171]
Rating: 6.4/10 (32 votes cast)

This script will alert a message to the visitors before they move to another webpage or even try to cancel or close a webpage.This script confirms site exit with an alert box.
Here is the sample script.

<html>
<head>
<script type="text/JavaScript"> 
function ExitPage()
{
alert ('Before You Leave:\n\nPlease Check our new tutorials on http://www.mistonline.in.\n\nMore than 250 tutorials.\n\nPlease submit your own tutorials for free\n\nA complete reference for webmasters!!!!!.');
getit()
}
function getit() {
askit = confirm("Leaving so soon? Why not stay a little longer!");
if (askit == true)
alert('Thanks');
else
if (askit == false)
alert("Visit again soon!");
}
</script>
</head>
<body onbeforeunload="ExitPage();">

VN:F [1.9.22_1171]
Rating: 6.4/10 (32 votes cast)
Alert a message before leaving a web page using javascript, 6.4 out of 10 based on 32 ratings

Incoming search terms:




coded by nessus

Leave a Reply

  • //22 Apr 2011

    Hi, Thnks for this amazing code.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
  • //14 Jun 2011

    thanx ….but i dont want the alert box when people click on the links within the site …what to do for that ?

    VA:F [1.9.22_1171]
    Rating: 5.0/5 (1 vote cast)
    • //28 Jun 2011

      What is your requirement then?

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
  • //18 Jul 2011

    how to make this only if a user i leaving site or closing browser, but not when he goes to a page within my site?

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
    • //19 Jul 2011

      You can create an alert box inside your website link using onclick attribute and javascript. Something like
      onClick=”javascript:alert(‘This is a test’)” , <a href=”" onClick=”javascript:alert(‘This is a test’)” >Test Link </a >
      I hope your issue has been resolved.

      VN:F [1.9.22_1171]
      Rating: 0.0/5 (0 votes cast)
  • //28 Oct 2012

    i want to popup a star rating window when after moving to another game (other game links ) in my website http://www.mygamegallery.com how can i achieve this.

    VA:F [1.9.22_1171]
    Rating: 0.0/5 (0 votes cast)
Close
Please support the site
By clicking any of these buttons you help our site to get better