Android重定向不起作用

csc*_*ler 9 javascript android

我需要将javascript文件重定向到用户指定的给定URI.

这是我如何做到这一点的简单示例:

function redirect(uri) {
  if(navigator.userAgent.match(/Android/i)) {
    document.location.href=uri;      
  }
  window.location.replace(uri);
}
Run Code Online (Sandbox Code Playgroud)

这适用于除Android设备之外的所有内容.iOS和所有现代Webbrowsers都支持window.location.replace(...),但Android设备不支持.

但是,如果我现在尝试使用此功能重定向,让我们说" http://www.google.com ",Android设备无法实际重定向到给定的网址.

现在只是我现在在这里愚蠢还是有另一个问题?

诚恳

ps重定向函数被调用作为发送的XML请求的回调,但这根本不应该是一个问题.

Sta*_*Sky 22

Android支持document.location没有href属性

尝试使用:

function redirect(uri) {
  if(navigator.userAgent.match(/Android/i)) 
    document.location=uri;      
  else
    window.location.replace(uri);
}
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息请点击这里