Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7952685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:56:07+00:00 2026-06-04T02:56:07+00:00

Please check my code in Chrome Browser, if you hit refresh you will be

  • 0

Please check my code in Chrome Browser, if you hit refresh you will be prompted with 2 options.

  1. Leave This Page and
  2. Stay on This Page

When I click the 2. Stay on this page button it must activate my custom function displayMsg()

Can any one provide me solution?

<script type="text/javascript">
function displayMsg() {
    alert('my text..');
}
</script>
<script type="text/javascript">
window.onbeforeunload = function(evt) {
  var message = 'Please Stay on this page and we will show you a secret text.';
  if (typeof evt == 'undefined') {
      evt = window.event;
  }       
  if (evt) {
      evt.returnValue = message;
      return message;
  }
  trace(evt);
} 
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:56:09+00:00Added an answer on June 4, 2026 at 2:56 am

    use a timer to listening for change variable :

    var vals=0;
    function displayMsg() {
        alert('my text..');
    }
    window.onbeforeunload = function evens(evt) {
    var message = 'Please Stay on this page and we will show you a secret text.';
      if (typeof evt == 'undefined') {
          evt = window.event;
      }       
        timedCount();
        vals++;
      if (evt) {
          evt.returnValue = message ;
          return message ;
      }
      trace(evt);
    } 
    
    function timedCount()
    {
    t=setTimeout("timedCount()",100);
    if(vals>0)
    {
        displayMsg();
        clearTimeout(t);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please check this code out it compiles and runs absolutely fine.. The question is
Can you guys please check this code, it is MVC3 Razor <p><strong><u>Skills:</u></strong> @foreach (var
please check with me where is the error in this ajax code to send
so basically, please check this code - Full code - <script type=text/javascript> $(document).ready(function() {
Please check this code: http://jsfiddle.net/rkumarnirmal/Rq7b2/2/ What I'm doing is I'm showing some text. If
I had a weird problem here. Please check the code below. I do not
Please check out my following code... public enum LogType { Debug, Info, Warn, Error,
Please check this: http://img62.imageshack.us/img62/3598/ieff.png why is it more height than in FF.. i want
Please check below screen shot. What is main difference between Master Page and MVC
Please check the below code, where I am creating multiple reference for an array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.