簡體   English   中英

在同一瀏覽器中打開新標簽頁時如何關閉標簽頁?

[英]How can close the tab when open the new tab in same browser?

我已經在瀏覽器選項卡中打開了一個網站。 現在,當我從該網站打開一個新標簽時,我想關閉該瀏覽器中的第一個標簽。

使用此腳本

<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>

您不能使用PHP關閉窗口,但可以使用此腳本

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

第一來源

第二個類似的演示

請嘗試這個

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM