开发者

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

开发者 https://www.devze.com 2023-01-06 03:34 出处:网络
I have opened a website in a browser tab. Now, when I open a new tab from this website, I开发者_如何学JAVA want to close the first tab in that browser.Use this script

I have opened a website in a browser tab. Now, when I open a new tab from this website, I开发者_如何学JAVA want to close the first tab in that browser.


Use this script

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


You cannot use PHP to close a window but you can use this script

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

First Source

Second Similar Demo


Please try this

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

精彩评论

暂无评论...
验证码 换一张
取 消