简体   繁体   中英

How to make a link redirect to a bootstrap modal with jQuery

I have a link that redirects to a product page by it's id, but I want to show a modal before it redirects. I would like the user to confirm that he has read it, and only redirect if he confirms, otherwise he would stay at the same page. (I apologize for the bad English)

You may find this example useful: http://www.bootply.com/63844

$('#btnYes').click(function() {
    // handle redirect here
    var link = $('#myModal').data('link');
    location.href = link;
    $('#myModal').modal('hide');
});

It uses a click handler on the link to trigger the modal, and then does the redirection once a button ( #btnYes ) inside the modal is clicked. The redirect link is defined using a data attribute on the link.

首先,链接到模态,然后如果单击某个按钮,则从模态链接到产品页面。

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