Android的重定向不工作 [英] Android redirect does not work
问题描述
我需要在由用户指定的JavaScript文件到一个给定URI重定向
I need to redirect in a javascript file to a given URI specified by the user.
因此,一个简单的例子我是如何做到这一点:
So a quick example how I do this:
function redirect(uri) {
if(navigator.userAgent.match(/Android/i)) {
document.location.href=uri;
}
window.location.replace(uri);
}
这工作得很好,除了对Android设备的一切。 iOS和所有现代化网页浏览器支持window.location.replace(...),但Android设备不这样做。
This works fine for everything except Android devices. iOS and all modern Webbrowsers support window.location.replace(...), however Android devices don't do that.
但是,如果我现在尝试使用此功能重定向,可以说为 http://www.google.com 一>的Android设备无法真正重定向到指定的网址。
But if I now try to redirect using this function, lets say to "http://www.google.com" the android devices fail to actually redirect to the given url.
现在只是我太傻了现在在这里还是有一个问题?
Now is it just me being stupid here right now or is there another problem?
诚恳
P.S。重定向功能被称为从XML请求发送的回调,但是这不应该是在所有的问题。
p.s. the redirect function is called as an callback from an XML request sent, but that should not be an issue at all.
推荐答案
Android支持 document.location
没有的href
属性
Android supports document.location
without the href
property
尝试使用:
function redirect(uri) {
if(navigator.userAgent.match(/Android/i))
document.location=uri;
else
window.location.replace(uri);
}
这篇关于Android的重定向不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!