<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<script language="javascript">
var win;
function openAndClose(url,t)
{
win = window.open(url);
window.setTimeout("win.close()",t);
}
</script><a href="#" onclick="javascript:openAndClose('http://www.baidu.com',5000)">baidu</a>&nbsp;
<a href="#" onclick="javascript:openAndClose('http://g.cn',5000)">google</a>
</body>
</html>

解决方案 »

  1.   


    <script>
    var win2, win3;
    function open2(){
    win2 = open("2.html");
    setTimeout("close2()",5000);
    }
    function open3(){
    win3 = open("3.html");
    setTimeout("close3()",5000);
    }
    function close2(){
    win2.close();
    }
    function close3(){
    win3.close();
    }
    </script><a href="javascript:open2();void(0);">open 2</a>
    <a href="javascript:open3();void(0);">open 3</a>
      

  2.   

    你好,你的代码是对的,但是如果我点击弹出的是一个模态对话框,我如何获得这个对话框对象啊?
    var a = window.showModalDialog('http://www.hao123.com');
    window.setTimeout("a.close()",1000);
    我这样写是不对的!
      

  3.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
    <script type="text/javascript">
    <!--
    //打开一个模式窗口
    function showModal(){
     showModalDialog('showModal.html',window,'dialogWidth=475px;dialogHeight=235px;status=no;help=no;scrollbars=no');
    }
    -->
    </script>
      </head>
      <body>
       <input type="button" name="sub" id="sub" onclick="showModal()" value="submit"/>
      </body>
    </html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>Untitled2</title>
    <script type="text/javascript">
    function winClose()//装载事件控制自己规定时间后关闭
    {
     window.setTimeout("window.close()",3000);
     
    }
    </script>
      </head>
      
      <body onload="winClose()">
       The window will be closed!!<br>
      </body>
    </html>
      

  4.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
    <script type="text/javascript">
    <!--
    //打开一个模式窗口
    function showModal(){
     showModalDialog('showModal.html',window,'dialogWidth=475px;dialogHeight=235px;status=no;help=no;scrollbars=no');
    }
    -->
    </script>
      </head>
      <body>
       <input type="button" name="sub" id="sub" onclick="showModal()" value="submit"/>
      </body>
    </html><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>Untitled2</title>
    <script type="text/javascript">
    function winClose()
    {
     window.setTimeout("window.close()",5000);
     
    }
    </script>
      </head>
      
      <body onload="winClose()">
       等下会关闭!!<br>
      </body>
    </html>
      

  5.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
    <script type="text/javascript">
    <!--
    //打开一个模式窗口
    function showModal(){
     showModalDialog('showModal.html',window,'dialogWidth=475px;dialogHeight=235px;status=no;help=no;scrollbars=no');
    }
    -->
    </script>
      </head>
      <body>
       <input type="button" name="sub" id="sub" onclick="showModal()" value="submit"/>
      </body>
    </html>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>Untitled2</title>
    <script type="text/javascript">
    function winClose()
    {
     window.setTimeout("window.close()",5000);
     
    }
    </script>
      </head>
      
      <body onload="winClose()">
       The window will be closed!!<br>
      </body>
    </html>
      

  6.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
    <script type="text/javascript">
    <!--
    //打开一个模式窗口
    function showModal(){
     showModalDialog('showModal.html',window,'dialogWidth=475px;dialogHeight=235px;status=no;help=no;scrollbars=no');
    }
    -->
    </script>
      </head>
      <body>
       <input type="button" name="sub" id="sub" onclick="showModal()" value="submit"/>
      </body>
    </html>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>Untitled2</title>
    <script type="text/javascript">
    function winClose()
    {
     window.setTimeout("window.close()",5000);
     
    }
    </script>
      </head>
      
      <body onload="winClose()">
       The window will be closed!!<br>
      </body>
    </html>