0

hello i have a Django base app and one of its apps is chatting with customer service.

i want when the customer clicks on the the [x] icon or close the window, a small popup window should come up that include:

1.a string like "thank you, and we hope you can take time and answer the survey:" 2. a button that directs the customer to the survey page.

i have this part of the chatting app java script file:

    window.onbeforeunload = function() {
       window.open ("http://gadgetron.store/male_chatbot/popup/"); <= i have tried it and it doesn't work
       $.ajax({
          type: 'GET',
          url: 'http://gadgetron.store/chatbot/run_python_clear_chatM/',});} 

thank you,

Eman
  • 127
  • 2
  • 9

2 Answers2

0

I tried some thing like that before, but I think the browser disabled the popup customization. and note that you need configure the ajax call as synchronous (check this). you can use window.onunload event handler, and then small popup with confirm and cancel button, if you click on confirm you script will be executed and the tab will closed

0

For user experience reasons, browsers do not allow opening Popups during the unload-phase, which this event is part of. The only thing you can do is open a popup, asking the user to confirm that he really wants to leave the page. This is achieved by returning any non-empty string from the event callback (ie. return "Are you sure you want to leave?"; where you currently call window.open). The text inside this confirmation window can no longer be influenced by the application for most modern browsers.

For information regarding popups during the unload phase, have a look at the WHATWG Spec, most importantly the ignore-opens-during-unload counter which blocks document.open when set to any value greater than 0.

Daniel Klischies
  • 1,095
  • 7
  • 14