我试图用browswerback按钮来获取wordpress ajax帖子,这意味着当用户点击浏览器的后退按钮时,之前加载的帖子标题就会显示出来,我想使用浏览器的后退按钮来显示上一篇帖子,为此我使用了这个代码,当用户点击该帖子时,它工作得很好,但它不能使用浏览器的后退按钮,我被这个问题卡住了。有人能告诉我这个问题的解决方案吗?
success: function(response) {
jQuery("#loading-animation").addClass('loadingstyle');
jQuery("#loading-animation").text(function(){
if(location.hash){
// We got a hash value! Lets take off the hash and smoke it.
var newhash = window.location.hash.substring(1);
jQuery("#loading-animation").html(response);
// uncomment the above code to see if it works.
}else{
alert("No hash available.");
// no hash value
}
$(".ajaxclick").click(function(e){
e.preventDefault();
window.location.hash = $(this).attr("href");
});
// $(window).on('hashchange', function() {
window.onhashchange = function(){
// hash changed. Do something cool.
if(location.hash){
var hash = window.location.hash.substring(1);
// console.log(response);
jQuery("#loading-animation").html(response);
}else{
// load home page
// jQuery("#loading-animation").html(response);
alert("No more content to show");
}
}
});
return false;
}发布于 2013-04-18 17:54:07
您正在使用e.preventDefault();,这会导致停止更多事件(单击)。
因此,从以下代码中删除e.preventDefault();
$(".ajaxclick").click(function(e){
e.preventDefault();
window.location.hash = $(this).attr("href");
});发布于 2013-04-18 18:25:57
你能用下面的代码替换onchange函数吗?
window.onhashchange = function(){
if(location.hash){
var hash = $('.ajaxclick').attr('href');
jQuery("#loading-animation").html(response);
}else{
alert("No more content to show");
}
} https://stackoverflow.com/questions/16079645
复制相似问题