JavaScript重定向问题

JavaScript Redirect Issue

本文关键字:问题 重定向 JavaScript      更新时间:2023-09-26

我正在用JavaScript构建一个跨平台的应用程序。我想重定向到不同的页面(在不同的域),但它不工作。我试着:

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

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

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

但是它又不起作用了。它给了我一个空白框。有人能帮帮我吗?

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

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