Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open URL on Bootstrap Modal close

Maybe I'm brain dead here, but I'm trying to do what seems should be an easy thing.

I am using Bootstrap to open a modal on page load depending on the value of specific variables. This all works great. However, when the modal opens and the user clicks ok (presumably after reading the info text), I want to page to redirect to a new page. I can't seem to figure out how to do this.

Any info on how to do

like image 479
Michael Reiland Avatar asked Dec 14 '13 07:12

Michael Reiland


People also ask

How do I open and close a Bootstrap modal?

Modals are built with HTML, CSS, and JavaScript. They're positioned over everything else in the document and remove scroll from the <body> so that modal content scrolls instead. Clicking on the modal “backdrop” will automatically close the modal. Bootstrap only supports one modal window at a time.

How do you open and close modals?

There are few ways to close modal in Bootstrap: click on a backdrop, close icon, or close button. You can also use JavaScript hide method. Click the button to launch the modal. Then click on the backdrop, close icon or close button to close the modal.

How do I open URL in modal popup?

Use the window open() method to popup a window tab as a modal with a URL. Note: JavaScript already has the ShowModalDialog function but it does not work in all browsers.

How do you close a modal in a modal?

Alternate solution Modal within Modalmodal('hide'); }); It will only close the inner modal and keep the initial modal open.


1 Answers

$(".modal").on("hidden.bs.modal", function () {
    window.location = "your-url";
});

http://getbootstrap.com/javascript/#modals-usage

You could also (and that is probably a better option) add a onclick handler to the button that the user has to click (because the hidden.bs.modal event also fires when the user closes the modal by pressing Esc or clicking the x button.

like image 111
Knaģis Avatar answered Sep 23 '22 03:09

Knaģis