I'm trying to redirect to a different page using javascript. It works nicely with开发者_运维百科 Firefox but not with Android. Here's a sample code:
<!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>
The goal is to redirect to google.com and I'm trying 3 different approaches. Firefox redirects immediately. Android prints the first location and then stops. If I comment out
window.location = "http://www.google.com";
then it prints the first two and stops. And so on. For some reason, I can read window.location just fine but when I try to modify it, the script hangs. Any help would be great. Using Android 2.2.
Try window.location.href
:
window.location.href = "http://www.google.com";
精彩评论