自动关闭当前窗口并使用新的URL地址打开新窗口

时间:2012-07-14 22:14:31

标签: javascript html

我使用以下代码进行自动关闭当前窗口并使用变量中的新URL打开新窗口。

代码有问题,不再工作,它正在关闭,但没有重新打开新窗口。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
          "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
  <head>
    <meta http-equiv="prahma" content="no-cache">
    <title>Auto Close and Open New window</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <script language="javascript">
      var url = "http://www.myweb.com/weather_control.php?"+Math.random()
      window.open(url,"","");
      window.open('', '_self', ''); 
      window.close();
    </script>

  </head>
  <body onload="closeIt();">
  </body>
</html>

您需要接受“允许此网站始终弹出”。

2 个答案:

答案 0 :(得分:0)

你知道http://www.myweb.com/weather_control.php是死页,对吗? 试着用这个:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<meta http-equiv="prahma" content="no-cache">
<title>Auto Close and Open New window</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<script language="javascript">
  var url = "http://www.myweb.com/weather_control.php?"+Math.random()
  window.open(url,"","MyTitle");
  window.open('', '_self', ''); 
</script>

</head>
<body onload="setTimeout(function(){window.close();},2000)">
</body>
</html>

答案 1 :(得分:0)

试试这个

<a>