我正在尝试使用javascript重定向到其他页面。它适用于Firefox,但不适用于Android。这是一个示例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta name="viewport" content="width=device-width" />
<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript">
document.write("1: " + window.location.href + "<br />");
window.location = "http://www.google.com";
document.write("2: " + window.location.href + "<br />");
window.location.href = "http://www.google.com";
document.write("3: " + window.location.href + "<br />");
window.location.assign("http://www.google.com");
document.write("4: " + window.location.href + "<br />");
</script>
<title>Test</title>
</head>
<body>
</body>
</html>
目标是重定向到google.com,我正在尝试3种不同的方法。 Firefox会立即重定向。 Android打印第一个位置然后停止。如果我发表评论
window.location = "http://www.google.com";
然后打印前两个并停止。等等。出于某种原因,我可以读取window.location,但是当我尝试修改它时,脚本会挂起。任何帮助都会很棒。使用Android 2.2。
答案 0 :(得分:1)
尝试window.location.href
:
window.location.href = "http://www.google.com";