Displaying Notice before Leaving Website

39 views
Skip to first unread message

Matt Jajkowski

unread,
Jun 7, 2013, 6:07:59 PM6/7/13
to fanc...@googlegroups.com
Hi all,

I want to use FancyBox to initiate a popup that shows a notice when a link is clicked, when the user clicks continue or OK then the browser window will redirect to the link.  Can fancybox do something like that? 

Thanks,
Matt

JFK

unread,
Jun 7, 2013, 9:29:15 PM6/7/13
to fanc...@googlegroups.com
Just for fun

You can have this html
<a class="fancybox" href="http://stackoverflow.com">go to stackoverflow site</a>
<div id="confirm" style="display: none">
    <p>are you sure you want to leave this page?</p><br />
    <a href="javascript:;" class="confirm yes">yes</a>
    <a href="javascript:;" class="confirm no">no</a>
</div>

and this script
$(".fancybox").on("click", function(e){
    e.preventDefault();
    var theSite = this.href;
    $.fancybox("#confirm",{
        modal: true,
        afterShow: function(){
            $(".confirm").on("click", function(event){
                if($(event.target).is(".yes")){
                    window.location.href = ""+ theSite +"";
                } else if ($(event.target).is(".no")){
                    $.fancybox.close();
                }
            });
        }
    })
});

See demo at http://jsfiddle.net/8KdD4/show/
Code http://jsfiddle.net/8KdD4/
Reply all
Reply to author
Forward
0 new messages