0

Here's the code. I need to show pop up window, when user leave the window without using jquery. Anybody can help?

  <script type="text/javascript">
      function addEvent(obj, evt, fn) {
          if (obj.addEventListener) {
              obj.addEventListener(evt, fn, false);
          }
          else if (obj.attachEvent) {
              obj.attachEvent("on" + evt, fn);
          }
      }
      addEvent(window,"load",function(e) {
          addEvent(document, "mouseout", function(e) {
              e = e ? e : window.event;
              var from = e.relatedTarget || e.toElement;
              if (!from || from.nodeName == "HTML") {
                  // stop your drag event here
                  console.log("leave window");
              }
          });
      });
      </script>
jhbkhbds
  • 1
  • 3
  • 1
    Possible duplicate of [this](http://stackoverflow.com/questions/4067796/how-to-create-popup-window-when-browser-close) – Rick Jul 10 '15 at 13:34
  • @putvande Yep, pretty much, or just `addEvent(window, 'unload', function)`. It's really that easy. – John Weisz Jul 10 '15 at 13:36
  • it cant be alert, i need stg like this https://www.youtube.com/watch?v=wjSLNPGnUMo – jhbkhbds Jul 10 '15 at 13:36

0 Answers0