JavaScript重定向问题

时间:2016-11-16 08:32:44

标签: javascript html cross-domain cross-platform

我正在使用JavaScript构建跨平台应用。我想重定向到另一个页面(在不同的域中),但它无法正常工作。我试过了:



<html>

<head>
  <script>
    function redir() {
      window.location.href = "http://www.example.com";
    }
  </script>
</head>

<body onload="redir()">

</body>

</html>
&#13;
&#13;
&#13;

它给了我一个空白页面。我尝试使用不同的代码,我尝试iframe这样:

&#13;
&#13;
<html>

<head>

</head>

<body>
  <iframe src="http://www.example.com" />
</body>

</html>
&#13;
&#13;
&#13;

但它没有再奏效。它给了我一个空白的iframe。有人能帮助我吗?

2 个答案:

答案 0 :(得分:1)

&#13;
&#13;
function Redirect() {
  window.location="https://www.tutorialspoint.com";
}
&#13;
<form>
  <input type="button" value="Redirect Me" onclick="Redirect();" />
</form>
&#13;
&#13;
&#13;

答案 1 :(得分:-1)

<body onload="redir()"></body>