Issue with event.returnValue Deprecated Recommendation in Chrome Console
When attempting to execute the JavaScript code below, you may encounter a warning in the Google Chrome console:
$(document).ready(function () { $("#changeResumeStatus").click(function () { $.get("{% url 'main:changeResumeStatus' %}", function (data) { if (data['message'] == 'hidden') { $("#resumeStatus").text("скрыто"); } else { $("#resumeStatus").text("опубликовано"); } }, "json"); }); });
The warning reads, "event.returnValue is deprecated. Please use the standard event.preventDefault() instead."
Explanation
This warning arises because event.returnValue is an outdated property for preventing default browser actions. Its replacement, event.preventDefault(), adheres to modern web standards and is recommended for use.
jQuery Compatibility
In jQuery версии 1.10.2 (#changeResumeStatus being a span) still defaults to event.returnValue. However, jQuery 1.11 and later versions use event.preventDefault() by default.
Solution
To resolve the issue, you can manually add event.preventDefault() to the click event handler:
$("#changeResumeStatus").click(function (event) { event.preventDefault(); $.get("{% url 'main:changeResumeStatus' %}", function (data) { if (data['message'] == 'hidden') { $("#resumeStatus").text("скрыто"); } else { $("#resumeStatus").text("опубликовано"); } }, "json"); });
The above is the detailed content of What is the Recommended Replacement for the Outdated event.returnValue in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!