是否支持Android window.location.replace或任何同等? [英] Does Android support window.location.replace or any equivalent?
问题描述
看来,Android的浏览器不正确实施 window.location.replace
。
在大多数浏览器,调用 window.location.replace
将取代目前使用的URL传递给它的URL。
当用户浏览其他地方,那么点击回来,他们将返回传递给 window.location.replace
的URL,而不是URL,他们是在之前 window.location.replace
被调用。
Android浏览器似乎不正确地实现这一点。
在Android浏览器,用户将被引导回的原始URL 的,而不是一个传递到 window.location.replace
。
您可以测试自己这一点这里。
那么,有没有在Android的重写历史的任何其他方式?或将我只是生活在没有该功能,为Android用户?
解决方案我有同样的问题,并结束了与code类似于克里斯建议,但我改变了if语句使用Modernizr的的特征检测
如果(!(window.history&安培;&安培; history.replaceState)){
window.history.replaceState({},document.title时,基地+片段);
} 其他 {
location.replace(基地+片段);
}
除非你有特殊原因的设备检测,特征检测是preferred,因为它基本上支持所有设备,甚至是未来的。
It seems that the Android browser doesn't properly implement window.location.replace
.
In most browsers, calling window.location.replace
will replace the current URL with the URL passed to it.
When the user navigates somewhere else then clicks back, they'll be returned to the URL that was passed to window.location.replace
, rather than the URL that they were at before window.location.replace
was called.
The Android browser doesn't seem to implement this properly.
In the Android browser, the user will be directed back to the original URL rather than the one passed to window.location.replace
.
You can test this for yourself here.
So is there any alternative way to re-write history in Android? Or will I just have to live without that feature, for Android users?
I had the same issue and ended up with code similar to chris suggestion, but I changed the if statement to use modernizr's feature detection. If you're not using modernizr the code would look something like this:
if(!!(window.history && history.replaceState)){
window.history.replaceState({}, document.title, base + fragment);
} else {
location.replace(base + fragment);
}
Unless you have a specific reason for device detection, feature detection is preferred since it basically supports all devices, even future ones.
这篇关于是否支持Android window.location.replace或任何同等?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!