Confirm redirect (Javascript)

by spyka (http://www.spyka.net)

This code asks users to confirm that they want to continue before being redirected to another website or page.

Place the first part in the <head></head> tags and use the second part to link to the snippet.

Code:
<!-- Place in <head></head> tags -->
<script type="text/javascript">
function con_redir(url) {
    var msg = 'Are you sure you want to continue?' // Message to users
    if(confirm(msg)) {
        location.href=url;
    }
}
</script>

<!-- Example usage -->
<a href="javascript:con_redir('http://www.google.com')">Go to google.com</a>

Code demo

Confirm redirect online demo

Help and comments

Discuss this and other scripts in our webmaster foruns

Learn more about our forums