1,105,281 Community Members

how to detect browser close and refresh event

Member Avatar
Gauri_1
Newbie Poster
1 post since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi ,
I am trying to detect browser close and refresh event when user clicks on browsers button for refresh and close, but still not get any sloution.
My project is in PHP. i try the folling code : -

  window.onbeforeunload = function(event) {
     alert("dsghjkadghjl");
  }

  $(function () {
          $("a").click(function() {
            window.onbeforeunload = null;
          });
        });

         $(document).bind('keypress', function(e) {
            if (e.keyCode == 116){
              window.onbeforeunload = null;
            }
            else if(e.keyCode==8)
            {
             window.onbeforeunload = null;
            }
         });
         $("input[type=submit]").bind("click", function() {
             window.onbeforeunload = null;
        });

at alert i want to show the servey popup. but at the close on window not on refresh or nevigation between site pages or submit button. i able to handle the f5 and ctrl-r and a tag.

but still i am not able to detect refresh or close event of the browser. Please Help .

LastMitch
Deleted Member
 
0
 

how to detect browser close and refresh event

I don't think you can detect a browser like what you mention.

I mean you can used javascript to open and close a browser but detect to alert when it is close?

Member Avatar
almostbob
Nearly a Senior Poster
3,381 posts since Jan 2009
Reputation Points: 515 [?]
Q&As Helped to Solve: 424 [?]
Skill Endorsements: 14 [?]
 
0
 

If you do this, you will see a downgrade in your SER, traffic loss, and zero customer retention
nobody wants popup anything, especially when they are exiting
better is a styled popover, onload, that asks the client if they WANT to answer your survey, that disappears and stays gone on NO, or if focus is transferred to any other element on the page

Member Avatar
Troy III
Practically a Posting Shark
891 posts since Jun 2008
Reputation Points: 174 [?]
Q&As Helped to Solve: 119 [?]
Skill Endorsements: 10 [?]
 
0
 

If you do this, you will see a downgrade in your SER, traffic loss, and zero customer retention nobody wants popup anything, especially when they are exiting

I encourage you to type a letter in the box below and try to navigate away from this page.

Member Avatar
almostbob
Nearly a Senior Poster
3,381 posts since Jan 2009
Reputation Points: 515 [?]
Q&As Helped to Solve: 424 [?]
Skill Endorsements: 14 [?]
 
0
 

the prompt on DaniWeb is not a survey,
during a submission that the poster has begun, a confimation that the poster wishes to discard what may be a significant amount of effort and thought.
note a difference in intent, to confirm a user wants to discard their input
Search spiders are intelligent enough to determine code value within limitations, anything that can be considered malignant code,
New reality show, Are you smarter than a WebSpider? dont think it will happen

Goto MS, Apache, and you get an initial popover layer that asks you if you wish to complete their surveys at the completion of your task, the choice is permananent in the session

Member Avatar
Troy III
Practically a Posting Shark
891 posts since Jun 2008
Reputation Points: 174 [?]
Q&As Helped to Solve: 119 [?]
Skill Endorsements: 10 [?]
 
0
 

To tell you the truth, I don't see the difference...
[?] What webspider!

Member Avatar
almostbob
Nearly a Senior Poster
3,381 posts since Jan 2009
Reputation Points: 515 [?]
Q&As Helped to Solve: 424 [?]
Skill Endorsements: 14 [?]
 
0
 

about the web spider, I dunno, pebkac error dont remember why I typed that, what it referred to, must have been something, but its gone now

the difference, DaniWeb's prompt,
somebody spent half an hour debugging somebody else's code, the solution isnt lost, its for the user's benefit
a different thing entirely than stopping a person navigating away from the page, for the website's benefit

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: