@junioract

Как заставить history back быстро вернуться назад?

Добрый вечер , на сайте реализовано аякс ссылки контент подгружается но если нажать назад то страница перегружается и возвращается назад , это не совсем удобно если я подгружаю публикации на главной , перехожу в статью и при попытки вернуться назад ( На то место откуда перешел ) Он показывает мне начало главной страницы
Прошу помочь где что неправильно написано
var box = $('#contnet');
           $(document).on('click', 'a[data-ajax]', function(e) {
               Wo_StartBar();
               window.post = 0;
               var url = $(this).attr('data-ajax');
               e.preventDefault();
               if (!ISAPI) {
                 if (url == '?index.php?link1=home') {
                    $get_value = $('#json-data').val();
                    if ($get_value) {
                        $('#load-more-posts').hide();
                        json_data = JSON.parse($('#json-data').val());
                        if (json_data.page == 'home') {
							document.getElementById('posts').innerHTML = '<div class="post-card"> <div class="loading-box"> <div class="head white-space"> <div class="head_1"></div><div class="head_2"></div><div class="head_3"></div><div class="head_4"></div></div><div class="body white-space"> <div class="body_1"></div><div class="body_2"></div><div class="body_3"></div><div class="body_4"></div><div class="body_5"></div><div class="body_6"></div><div class="body_7"></div></div></div></div><div class="post-card"> <div class="loading-box"> <div class="head white-space"> <div class="head_1"></div><div class="head_2"></div><div class="head_3"></div><div class="head_4"></div></div><div class="body white-space"> <div class="body_1"></div><div class="body_2"></div><div class="body_3"></div><div class="body_4"></div><div class="body_5"></div><div class="body_6"></div><div class="body_7"></div></div></div></div>';
                            loadposts();
                            window.history.pushState({state:'new'},'', websiteUrl);
                            $("html, body").animate({ scrollTop: 0 }, 100);
                            $('.user-details, .pac-container, .lightbox-container').remove();
                            Wo_clearPRecording();
                            Wo_CleanRecordNodes();
                            Wo_stopRecording();
                            Wo_StopLocalStream();

                            return false;
                        }
                    }
                 }
                 $.post(Wo_Ajax_Requests_Filee() + url, {url:url}, function (data) {
                     $('.user-details').remove();
                     json_data = JSON.parse($(data).filter('#json-data').val());

                     if ($('.message-option-btns').length > 0) {
                          if (json_data.url == 'index.php?index.php?link1=home') {
                              window.location.href = websiteUrl;
                          } else {
                             window.location.href = json_data.url;
                          }
                          return false;
                     }
                     //document.getElementById('#contnet').innerHTML = data;
                     box.html(data);
                     if (json_data.is_css_file == 1) {
                       $('.styled-profile').remove();
                       $('footer').append(json_data.css_file);
                       $('.extra-css').html(json_data.css_file_header);
                     } else {
                       $('.styled-profile').attr('href', '');
                       $('.extra-css').empty();
                     }
                     Wo_clearPRecording();
                     Wo_CleanRecordNodes();
                     Wo_stopRecording();
                     Wo_StopLocalStream();
					 if (json_data.page == 'timeline') {
                        $('.content-container').addClass('container-fluid');
                        $('.content-container').removeClass('container');
                     } else {
                        $('.content-container').addClass('container');
                        $('.content-container').removeClass('container-fluid');
                     }
                     if (json_data.page == 'home') {
                       $('.filterby li.filter-by-li').on('click', function (e) {
                         $('.filterby li.filter-by-li').each(function(){
                           $(this).removeClass('avtive');
                           $(this).find('i').addClass('hidden');
                         });
                          $(this).find('i').removeClass('hidden');
                          $(this).addClass('avtive');
                        });
                       window.history.pushState({state:'new'},'', websiteUrl);
                       //window.history.pushState({}, "<?php echo $wo['config']['site_url']?>", websiteUrl);
                     } else {
                       window.history.pushState({state:'new'},'', json_data.url);
                       //window.history.pushState({}, "<?php echo $wo['config']['site_url']?>", json_data.url);
   window.onpopstate = function(e) {
        window.location, true;
    };


                     }
                     $('.postText').autogrow({vertical: true, horizontal: false, height: 200});
                      window.onpopstate = function(event) {
                        $(window).unbind('popstate');
                        window.location.href = document.location;
                      };
                     if (json_data.page == 'timeline' || json_data.page == 'page' || json_data.page == 'group') {
                       $('.content-container').css('margin-top', '25px');
                       $('.ad-placement-header-footer').find('.contnet').css('margin-top', '20px');
                     } else {
                       $('.content-container').css('margin-top', '45px');
                       $('.ad-placement-header-footer').find('.contnet').css('margin-top', '0');

                     }
                     if (json_data.is_footer == 1 && $('.second-footer').css('display') == 'none') {
                        $('footer .footer-wrapper').show();
                     }else if(json_data.is_footer == 1 && $('.second-footer').css('display') != 'none'){

                     } else {
                      if ($(window).width() < 720) {
                        $('footer .footer-wrapper').show();
                      } else {
                        $('footer .footer-wrapper, .second-footer').hide();
                      }
                     }
                     document.title = decodeHtml(json_data.title);
                     document_title = decodeHtml(json_data.title);
                     $("html, body").animate({ scrollTop: 0 }, 150);
                     Wo_FinishBar();
                     $('#hidden-content').empty();
                     $('#users-reacted-modal').modal("hide");
                 });
                 $('.user-details, .pac-container, .lightbox-container').remove();
               }
           });
       });
  • Вопрос задан
  • 74 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы