Posted By

paulomonteiro84 on 04/06/16


Tagged

javascript js browser traffic exit unload


Versions (?)

exit traffic


 / Published in: JavaScript
 

This is an easy and simple solution for exit traffic.

  1. <script>
  2. jQuery(document).ready(function() {
  3. var url = 'http://www.snipplr.com';
  4.  
  5. $('a').on('click', function () {
  6. $(window).unbind("beforeunload");
  7. });
  8.  
  9. $('form').on('submit', function () {
  10. $(window).unbind("beforeunload");
  11. });
  12.  
  13. $(window).on("beforeunload", function (e) {
  14. $(window).unbind("beforeunload");
  15.  
  16. setTimeout(function () {
  17. window.location = url;
  18. }, 0);
  19.  
  20. e.returnValue = message;
  21. return message;
  22. });
  23. });
  24. </script>

Report this snippet  

You need to login to post a comment.