如何在同一浏览器中打开新选项卡时关闭选项卡?

时间:2010-07-07 05:55:02

标签: javascript

我在浏览器标签中打开了一个网站。现在,当我从这个网站打开一个新标签时,我想关闭该浏览器中的第一个标签。

3 个答案:

答案 0 :(得分:3)

使用此脚本

<html>
    <head>
        <script type="text/javascript">
            function click1() {
                window.open("http://127.0.0.1/");
                window.open("http://127.0.0.1/wordpress/?page_id=2");
            }
            function close1() {
                var c="http://127.0.0.1/";
                c.close();
            }
            function newwin (urllink) {
                newwindow = window.open( urllink ,'newwin')
            }
        </script>
    </head>
    <body>
        <a href="javascript:newwin('http://www.bbc.co.uk')">bbc</a><br>
        <a href="javascript:newwin('http://www.google.co.uk')">google</a>
        <form>
            <input type="button" value="close me!!" onClick="close1()"/>
            <input type="button" value="Close" onClick="window.newwindow.close()">
        <form>
    </body>
</html>

答案 1 :(得分:1)

您无法使用PHP关闭窗口,但可以使用此脚本

<script language="javascript" type="text/javascript"> 
    function closeWindow() { 
      window.open('','_parent',''); 
      window.close(); 
    } 
</script> 

First Source

Second Similar Demo

答案 2 :(得分:0)

请试试这个

<script type="text/javascript">
function newwin (urllink) {
newwindow = window.open( urllink ,'newwin')
}
</script>
相关问题