Open a new window on user leave

Written by @kerixa 21 August 2012

Sometimes we need a code to open and close a new tab or ask a question before closing the tab in the browser. The following code does this job, and with it we have a link that opens a new tab for us. If you click on the second link, it asks if you are sure you want to close this window and it will be closed if approved.

Code Snippet:

                                                
                                                <!-- this script is provided by https://www.htmlfreecode.com coded by: Kerixa Inc. -->
<div>
    Html Free Code
</div>

<a href="http://www.htmlfreecode.com/" target="blank">Open</a>
<a href="#" onclick="closethis();return false;">close</a>

<script>
    function closethis() {
        if (confirm("Close Window?")) {
            close();
        }
    }
</script><a target='_blank' href='https://www.htmlfreecode.com' style='font-size: 8pt; text-decoration: none'>Html Free Codes</a>                                                
                                            

Example:


About @kerixa

I am Krishna Eydat. I studied Software Engineering at University of Waterloo in Canada. I lead a few tech companies. I am passionate about the way we are connected. I would like to be part of something big or be the big deal!

K

Comments


Here you can leave us commments. Let us know what you think about this code tutorial!

0 / 300

TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: carfaoui, Ali7hry, alexnicola, Adam20, Prashanthcs11
advertisement 2