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.
function btnA() {
    window.location.href = '';
    alert('Returning to Inbox!');
    return false;

The StationExistsModal.Hide(); line works fine. However the window.location.href = ''; 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.

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:
function GoToInbox() {
    window.location.href = '';
    return false;

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

<!-- 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 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 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>
Updated 4-Oct-23 4:19am

1 solution

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

	<script type="text/javascript">
		function redirect() {

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
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