Michael Reiland
Michael Reiland

Reputation: 849

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

Upvotes: 6

Views: 15896

Answers (3)

M P
M P

Reputation: 1

it also dismiss the modal , modal should be dismissed after 10-20 seconds or manualy by closing it , is it possible .

Upvotes: 0

Knaģis
Knaģis

Reputation: 21485

$(".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.

Upvotes: 8

Carol Skelly
Carol Skelly

Reputation: 362360

Along the lines of @Knagis additional option, you can use onclick to change the window.location, and the data-dismiss=modal attribute in the same link..

<a href="" data-dismiss="modal" onclick="javascript:window.location='http://google.com'">Visit Google.</a>

Demo: http://www.bootply.com/oKgjTJXGTq

Upvotes: 4

Related Questions