Advertisement
Guest User

Safe Bouncerate

a guest
Oct 23rd, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <script type="text/javascript">
  2. var back_to_url= "http://example.com/halaman-yang-muncul-jika-di-klik-back.html";//Ganti url ini
  3.  
  4.  
  5.  
  6.  
  7.  
  8. var safe_bouncerate= true;
  9. function _createelements(){
  10. if(safe_bouncerate){
  11. var a=document.createElement('a');
  12. a.href=document.referrer;
  13. a.hostname;
  14. if(document.referrer !== undefined && document.referrer.length > 0 && a.hostname == window.location.hostname){
  15. safe_bouncerate = false;
  16. }
  17. }
  18. }
  19. (function() {
  20. if (!window.addEventListener)
  21. return;
  22. var blockPopstateEvent = document.readyState!='complete';
  23. window.addEventListener('load', function() {
  24. setTimeout(function(){ blockPopstateEvent = false; }, 0);
  25. }, false);
  26. window.addEventListener('popstate', function(evt) {
  27. if (blockPopstateEvent && document.readyState=='complete') {
  28. evt.preventDefault();
  29. evt.stopImmediatePropagation();
  30. }
  31. }, false);
  32. })();
  33. function executewhenclickback(){
  34. var rhash = '#forward';
  35. var currentUrl = window.location.href;
  36. _createelements();
  37. if(!safe_bouncerate) return;
  38. window.history.replaceState(null, null, currentUrl + rhash);
  39. window.history.pushState(null, null, currentUrl);
  40. window.addEventListener('popstate', function() {
  41. if (location.hash == rhash) {
  42. history.replaceState(null, null, location.pathname);
  43. location.replace(back_to_url);
  44. }
  45. });
  46. }
  47. executewhenclickback();
  48. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement