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
3 Answers
Reset to default 3You 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745287362a4620643.html
评论列表(0条)