admin管理员组

文章数量:1418361

I have a site built with Asp.Net mvc where I show a list of products and automatically fill in the default purchasing amount for those products in each corresponding input field.

However when i navigate to a different product catalog using the anchor tag the 'Changes may not be saved' alert pops up presumably because of the default values entered in the input fields.

Now I have tried to disable this alert using the following in my shared layout page inside of a script tag:

  • window.onbeforeunload = null
  • window.beforeunload = null

I have also tried various answers from similar questions but nothing seems to help.

Does anyone know how I can get rid of this alert? Thanks in advance.

I have a site built with Asp.Net mvc where I show a list of products and automatically fill in the default purchasing amount for those products in each corresponding input field.

However when i navigate to a different product catalog using the anchor tag the 'Changes may not be saved' alert pops up presumably because of the default values entered in the input fields.

Now I have tried to disable this alert using the following in my shared layout page inside of a script tag:

  • window.onbeforeunload = null
  • window.beforeunload = null

I have also tried various answers from similar questions but nothing seems to help.

Does anyone know how I can get rid of this alert? Thanks in advance.

Share Improve this question asked May 18, 2021 at 9:05 KyllionKyllion 111 silver badge3 bronze badges 2
  • 6 That alert is not automatic, it es from your own code. – Jamiec Commented May 18, 2021 at 9:10
  • This seems to have been the problem, apparantly a directive was added by a colleague to throw this alert. – Kyllion Commented May 18, 2021 at 9:30
Add a ment  | 

3 Answers 3

Reset to default 3

You may have more success using this for jQuery:

$(window).off('beforeunload');

You can also read about some of the caveats and potential pitfalls of the beforeunload event here.

Update:

Just to clarify a point further from a ment @Jamiec left, the event should be triggered in your project somewhere, try searching for beforeunload to see where it originates.

Using Jquery Try below code.

$(window).off('beforeunload');

This is best option for changes that you made may not be saved popup.

If you use javascript then you can use below code,

window.onbeforeunload = function () {return null;};

Apparantly the alert was being called from a directive created by a colleague, by disabling this directive the alert no longer appears.

Thanks to Jamiec for notifying me.

本文标签: javascriptHow to disable 39Changes you made may not be saved39 when clicking an anchor tagStack Overflow