[英]pushstate/pop state issue on IOS - history api/javascript
我僅在iPhone和iPad上有一個奇怪的問題。 我建立了以下功能:
在電子商務網站上,當用戶在結帳成功頁面上單擊一次瀏覽器的“后退”按鈕時,我會將他重定向到首頁。 這在所有主要的瀏覽器上都很好用。
但是,在IOS上,在單擊“后退”按鈕之前,頁面會自動重定向到首頁(在結帳成功頁面上)
我有以下代碼:
(function() {
var SuccessPage ={
extractDomain:function(url){
var domain;
if (url.indexOf("://") > -1) {
domain = url.split('/')[2];
}
else {
domain = url.split('/')[0];
}
domain = domain.split(':')[0];
return domain;
}
}
if(window.location.href.indexOf("checkout/onepage/success") > -1) {
history.pushState(null, null, window.location.href);
window.addEventListener("popstate", function(e) {
window.location.assign("http://"+SuccessPage.extractDomain(window.location.href))
});
}
})();
我試過在彈出狀態事件上使用set timeout ..但沒有雪茄:(而且我不知道為什么IOS無法理解此代碼。
請幫忙
得到它的工作:
if(window.location.href.indexOf("checkout/onepage/success") > -1) {
if(window.history && history.pushState && history.state !== undefined){
history.pushState(null, null, window.location.href);
window.addEventListener("popstate", function(event) {
if(navigator.userAgent.match(/(iPod|iPhone|iPad)/)){
if(!page_loaded){
page_loaded = true;
return false;
}else{
window.location.assign("http://"+SuccessPage.extractDomain(window.location.href))
}
}else{
window.location.assign("http://"+SuccessPage.extractDomain(window.location.href))
}
},false);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.