history.back()在safari中不重新加载js问题怎么解决
如果是ios的,先判断出来,location.href定位回去
$("#backPrev").attr("href","javascript:void(0);").click(function(){
if (/(iPhone|iPad|iPod)/i.test(navigator.userAgent)) {
window.location.href = window.document.referrer;
} else { window.history.go("-1"); }
});
判断safari可以
if(isSafari=navigator.userAgent.indexOf("Safari")>0) {
return "Safari";
}
但是这样会导致自带的返回按钮混乱,比如,从a页面进入b页面,然后b页面搜索进入c页面,c页面返回,进入b页面,但是由于是链接,此时b页面返回仍然是c页面。
终极解决方法:
在跳转页面之前,改写当前页面地址
$("#backPrev").attr("href","javascript:void(0);").click(function(){
if (/(iPhone|iPad|iPod)/i.test(navigator.userAgent)) {
changeCurrentUrl();
window.location.href = window.document.referrer;
} else { window.history.go("-1"); }
});
function changeCurrentUrl(){
var replaceUrl = window.location.href+"?i="+new Date().getTime();
history.replaceState(null,"",replaceUrl);
}