Guest User

Untitled

a guest
Sep 16th, 2019
129
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var CRedirectName = 'page_id_mirntk';
  2. var redirectLastPage = true;
  3.  
  4.  
  5.  
  6. var cookee_page_id;
  7. var pages = [
  8. {id: 1, page: "1.php"},
  9. {id: 2, page: "2.php"},
  10. {id: 3, page: "3.php"},
  11. {id: 4, page: "4.php"},
  12. ];
  13.  
  14.  
  15.  
  16. function setCookie(name, value, days) {
  17. localStorage[name] = value;
  18. }
  19.  
  20. function readCookie(name) {
  21. if (localStorage[name] == undefined) {
  22. return null;
  23. }
  24. else
  25. return parseInt(localStorage[name]);
  26. }
  27.  
  28.  
  29. function redirectPage(page_idLocal) {
  30. var page = '';
  31.  
  32.  
  33. if (page_idLocal > pages.length) {
  34. page_idLocal = pages.length;
  35. setCookie(CRedirectName, page_idLocal, 30);
  36. }
  37. else if (page_idLocal < 1) {
  38. page_idLocal = 1;
  39. setCookie(CRedirectName, page_idLocal, 30);
  40. }
  41.  
  42.  
  43. for (var i = 0; i < pages.length; i++) {
  44. if (pages[i].id == page_idLocal) {
  45. page = pages[i].page;
  46. break;
  47. }
  48. }
  49. if (redirectLastPage) {
  50. window.location.href = page;
  51. document.location = page;
  52. }
  53.  
  54. // location.reload();
  55. }
  56.  
  57. function load() {
  58. cookee_page_id = readCookie(CRedirectName);
  59. if(cookee_page_id == null) {
  60. setCookie(CRedirectName, page_id, 30);
  61. }
  62. // console.log(cookee_page_id);
  63. }
  64.  
  65. function init() {
  66. if(cookee_page_id != null) {
  67. if(+page_id < +cookee_page_id) {
  68. redirectPage(cookee_page_id);
  69. }
  70. if(+page_id > +cookee_page_id) {
  71. setCookie(CRedirectName, page_id, 30);
  72. }
  73. }
  74. }
  75.  
  76. window.onload = function() {
  77. load(),
  78. init();
  79.  
  80.  
  81.  
  82.  
  83.  
  84. };
  85. load();
  86. init();
RAW Paste Data