history ajax 回退历史 function setState(p) { var list = ''; if ($('.goods-list')) { list = $('.goods-list'); } else if ($('.first-list')) { list = $('.goods-list'); } else if ($('.ads-list')) { list = $('.ads-list'); } else { } var stat
function setState(p) {
var list = '';
if ($('.goods-list')) {
list = $('.goods-list');
} else if ($('.first-list')) {
list = $('.goods-list');
} else if ($('.ads-list')) {
list = $('.ads-list');
} else {
}
var statusUrl = window.location.href;
var stateobj = ({
//里面存放url等信息,stateobj将作为pushState()的第一个参数
url: statusUrl,
list: list.html(),
title: '',
page: p
});
if (window.history.state) {
window.history.replaceState(stateobj, null, statusUrl); //将当前url加入堆栈中
} else {
window.history.pushState(stateobj, null, statusUrl); //将当前url加入堆栈中
}
};
function aClick() {
$('a').click(
function (event) {
event.preventDefault();
if ($('.goods-list')) {
var page = $('.goods-list').data('page');
} else {
var page = 0;
}
if (!$(this).hasClass('tb_app')) {
setState(page);
}
var cms_ua = navigator.userAgent.toLowerCase();
if ($(this).hasClass('ui-link') && cms_ua.match(/MicroMessenger/i) == 'micromessenger') {} else {
window.location.href = $(this).attr('href');
}
}
)
}
引用
if(window.history.state){
$('.goods-list').html(window.history.state.list);
var p = window.history.state.page;
}else{
var p = 2;
}
