I have the following modal on my master page as a loading message with a spinning gif whenever a page is loading.
<div id="divModal" class="modal fade" role="dialog">
<div id="divModalDialog" class="modal-dialog">
<div id="divModalContent" class="modal-content" style="text-align: center;">
<div id="divModalBody" class="modal-body">
<img src="/Images/Loading.gif" width="200" alt="Loading..." />
<div id="divMessage" style="margin-top: 10px">
<b>Please Wait...</b>
</div>
</div>
</div>
</div>
</div>
I'm using the following script to try to show and hide the modal.
<script type="text/javascript">
function showModal() {
$('#divModal').modal('show');
}
function hideModal() {
$('#divModal').modal('hide');
}
$(document).ready(showModal());
window.onload = hideModal();
</script>
Showing the modal in document.ready works fine. But when all the content on the page is finished loading, usually about 5 seconds, I want the modal to go away. From what I've read, putting the hide modal function in window.onload should work, but it doesn't. My modal pops up as soon as the page starts to load, but just keeps spinning indefinitely.
I have both of these functions right before the end of the body, as it seems that's the only place the show modal function will work. I've even put alerts and console logs in each function to make sure they're firing in the correct order, and they are. I get no errors when they fire either. But hide just isn't hiding the modal. Does anyone have any idea why this could be?
EDIT: I've gotten hideModel() to actually hide the model by wrapping it in setTimeout().
window.onload = setTimeout("hideModal()", 1000);
However, it just immediately hides the modal after however long the second parameter is, whether or not the page is finished loading.