Click here to Skip to main content
15,851,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a simple button to close a modal and go to the Inbox.aspx page.
JavaScript
function btnA() {
    StationExistsModal.Hide();
    window.location.href = 'https://mysite.com/Inbox.aspx';
    alert('Returning to Inbox!');
    return false;
}

The StationExistsModal.Hide(); line works fine. However the window.location.href = 'https://mysite.com/Inbox.aspx'; line will not do anything without that alert('Returning to Inbox!'); line. It simply will not work. What am I doing wrong? How do I get this to work?

What I have tried:

I've searched Google and YouTube for 4 days trying to get this to work and I have nothing.

EDIT:
This still does not work. Using the btnGoToInbox and the onclick GoToInbox function closes the modal, but the window.location.href still does nothing.
My current JS:
JavaScript
function GoToInbox() {
    window.location.href = 'http://www.google.com';
    return false;
}

My Current modal:
HTML
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#StationExistsBackdrop">
  Launch static backdrop modal
</button>

<!-- Modal -->
<div class="modal fade" id="StationExistsBackdrop" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="StationExistsBackdropLabel" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header StationExistsPopUp">
        <h1 class="modal-title fs-5" id="StationExistsBackdropLabel">Station Exists Error</h1>
        <%--<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>--%>
      </div>
      <div class="modal-body">
        <p style="font-size: 40px;color: #8a0303;text-shadow: 1px 1px 3px #000000;">Wheeeee!</p>
        <button class="btn btn-success" id="btnGoToInbox" onclick="GoToInbox();">Go To Inbox</button>
        <p style="font-size: 40px;color: #8a0303;text-shadow: 1px 1px 3px #000000;">w00t!</p>
      </div>
      <div class="modal-footer">
        <%--<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>--%>
        <button type="button" class="btn btn-success" data-bs-dismiss="modal">OK, I understand</button>
      </div>
    </div>
  </div>
</div>
Posted
Updated 4-Oct-23 4:19am
v3

1 solution

It's something else to do on your page. The following code works as expected:
HTML
<html>
<body>
	<button type="button" onclick="redirect()">Test!</button>

	<script type="text/javascript">
		function redirect() {
			window.location.href='https://www.yahoo.com';
		}
	</script>
</body>
</html>

I would suggest opening the developer tools in your browser before you click the button and look in the console window for any messages that pop up.

My first suspect is whatever library you're using for that "StationExistsModel" object, whatever that is.
 
Share this answer
 
v2
Comments
Timmy1729 3-Oct-23 17:59pm    
I have updated the question with the current code.
Dave Kreskowiak 3-Oct-23 18:31pm    
The problem has nothing to do with what you posted. Like I said, this is going to come down to whatever library/CSS/Javascript your page is loading. Nobody can diagnose that but you.
Timmy1729 4-Oct-23 9:34am    
Ok. Thank you for your help! :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900