Bootstrap modal appear after link is clicked and opens in a new window?

Hi there,

I am trying to have a Bootstrap modal open up after a user has clicked on a link that opens in a new window.

I can get the modal to show, but the link is not opening.

Can anyone suggest a way of achieving the link opening as well as the modal?

This is my pen:

Thanks!

If the browser follows the link you will never see the modal! It will navigate away before the modal is shown.

e.g. Add this js to the end of your demo.

$('#exampleModalCenter').on('shown.bs.modal', function (e) {
  var url = $('.button[data-target="#exampleModalCenter"]').attr("href");
  var windowName = "popUp";
  window.open(url, windowName);
});

What exactly are you trying to do here?

Do you want to show a modal first and then follow the link when the modal is closed? Or are you trying to open a modal in a new window?

Whichever of the above is required then you will certainly need js to do this.

1 Like

Hi,

Thanks for the reply.

Basically I have a contest listing website that will take the user to an external website in a new window. I then want the user to see a modal with a “share” box after they have visited to help gain some social interaction.

Thanks for the code, that worked great :slight_smile:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.