简体   繁体   中英

close a new pop up window in html

I'm using a form with submit button in html which opens a new window onclick of submit. Now i want this new window to be closed without user intervention.

i have tried below:

<script type="text/javascript">
var newWin;
function newWindow()
{
    alert('in newWindow');
    newWin=window.open('http://someurl','_blank');
    setTimeout(function(){newWin.close()}, 10);
    alert('closed..');
}
</script>

but this does seem to close the new window. It still stays open. Pls help.

Your Code is working Fine, only thing is you need to give some time to see that window, alert boxes not required

<script type="text/javascript">
var newWin;
function newWindow()
{
    newWin=window.open('http://www.google.co.in','_blank');
    setTimeout(function(){newWin.close()}, 5000);
}
</script>
<button onclick="newWindow()">open Window</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM