Why window.removeEventListener(beforeunload) is not working inside another function

Last Reply 10 days ago By dharmendr

Posted 13 days ago

I have function check() which is called onClick

function check() {
      $('#test').click()
    });
   }

i have a function which is called before check()

  function before(){ ....lines of code window.removeEventListener('beforeunload', check); }

I wish to disable alert & confirm popups(Changes you made may not be saved.) for every browser for the #test click event .But it didn't work confirm popups still occurs.

This is how beforeunload is initiated in my proj

 window.addEventListener('beforeunload', function (e) {...continues}

 why is it not working?

  
sam34567 has viewed this question 9 days ago.
Results 1 - 5 of 10 12
Posted 13 days ago

Hi sam34567,

Please share complete code and html.


Posted 13 days ago

Lets just simplify it more.

i have two button

  <asp:Button ID="btn" runat="server" CssClass="btncustom" Text="check" OnClientClick="check()" />

  <asp:Button ID="test" runat="server" CssClass="btncustom" Text="load"/>

I have this function check() which is called onClientClick event of above first button.

        function check() {
            window.removeEventListener('beforeunload', function (e) {
                      $('#test').click()
            }, false);
        }

This function raise another click event(e.g test.click).but for this button click i don't want any alert box(inbuild) to appear.So i wish to block it.


Posted 13 days ago

It doesn't display any alert box.

So will you please share the screenshot and complete code and html so that can check.


Posted 13 days ago Modified on 13 days ago
dharmendr says:

It doesn't display any alert box.

So will you please share the screenshot and complete code and html so that can check.

 How to attach image in reply from local machine


Posted 13 days ago

I am using JqueryUI for custom Confirm box when user clicks on a button.

Here is the script,

    function exit() {
            $("#dialog-confirm").dialog({
                resizable: false,
                height: "auto",
                width: 400,
                modal: true,
                buttons: {
                    "Proceed": function () {
                        callClick();
                    },
                    Cancel: function () {
                        $(this).dialog("close");
                    }
                }
            });
    }

Here is the HTML code

    <asp:Button ID="test" runat="server" Text="Exit" OnClick="test_click" />
    <div id="dialog-confirm" title="Proceed Confirmation?">
        <p>Are you sure you want to exit?</p>
    </div>
    <a href="#" id="exitLink" onclick="exit()">Exit</a>

When user click on proceed button i want to call another function.

        function callClick() {
            $('#test').click()
        }

But as soon as button is clicked alert popups appear along with my custom made alert popup.

i wish to disable the default popup.

please see below image for referrence