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
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.
版权声明:本文标题:javascript - How to disable 'Changes you made may not be saved' when clicking an anchor tag - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745287362a2651579.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论