Put modal('toggle') instead of modal(toggle)
$(function () {
$('#modal').modal('toggle');
});
Answer from Tamil Selvan C on Stack OverflowModal close definition - Bootstrap Studio Help - Bootstrap Studio Forum
Bootstrap modal - close modal when "call to action" button is clicked
How to trigger an event when bootstrap modal closes
Rails 7 Bootstrap 5 Modal
Videos
Put modal('toggle') instead of modal(toggle)
$(function () {
$('#modal').modal('toggle');
});
to close bootstrap modal you can pass 'hide' as option to modal method as follow
$('#modal').modal('hide');
Please take a look at working fiddle here
bootstrap also provide events that you can hook into modal functionality, like if you want to fire a event when the modal has finished being hidden from the user you can use hidden.bs.modal event you can read more about modal methods and events here in Documentation
If none of the above method work, give a id to your close button and trigger click on close button.
You need to bind the modal hide call to the onclick event.
Assuming you are using jQuery you can do that with:
$('#closemodal').click(function() {
$('#modalwindow').modal('hide');
});
Also make sure the click event is bound after the document has finished loading:
$(function() {
// Place the above code inside this block
});
enter code here
Remove your script, and change the HTML:
<a id="closemodal" href="https://www.google.com" class="btn btn-primary close" data-dismiss="modal" target="_blank">Launch google.com</a>
EDIT: Please note that currently this will not work as this functionality does not yet exist in bootstrap. See issue here.