event.returnValue is deprecated. Please use the standard event.preventDefault() instead
Asked Answered
R

7

224

I have this script:

<script>
$(document).ready(function () {
    $("#changeResumeStatus").click(function () {
        $.get("{% url 'main:changeResumeStatus' %}", function (data) {
            if (data['message'] == 'hidden') {
                $("#resumeStatus").text("скрыто");
            } else {
                $("#resumeStatus").text("опубликовано");
            }
        }, "json");
    });
});
</script>

I receive the following error in my Google Chrome console:

event.returnValue is deprecated. Please use the standard event.preventDefault() instead.

I am using jQuery v1.10.2 and #changeResumeStatus is a <span>.

What's wrong with my script?

Rinehart answered 18/11, 2013 at 10:12 Comment(5)
I think that's not an error, but merely a warning - this one can be safely ignored.Sawbuck
This warning is following lastest chrome update, don't worryEclat
You should look into escaping non-ascii strings.Walworth
@Walworth what for? my templates work completely fine in utf-8Rinehart
@AlexParakhnevich There's no single compelling reason to do so, but a few minor ones that creep up from time to time. My reaction was instinctive rather than well thought out, to be honest. In projects I'm working on right now, there's a guideline to not use non-ascii chars in literals, which I instituted in the past, because some external tools (typescript compiler) choked on such input. It works well enough in most cases, but sometimes eats up a lot of developer time when things go wrong. Anyway, .empty().append("text") is better expressed as .text("text").Walworth
G
204

This is only a warning: your code still works, but probably won't work in the future as the method is deprecated. See the relevant source of Chromium and corresponding patch.

This has already been recognised and fixed in jQuery 1.11 (see here and here).

Georgettegeorgi answered 18/11, 2013 at 10:27 Comment(9)
I doubt this anyone will break this anytime soon if it means causing all pages using JQuery < 1.11 to break.Bellbella
This warning also appears with jQuery 2.0.3 (most recent stable as of this comment), and the current milestone is set to 2.1, for the fix.Improvised
Does using jQuery 1.11 will fixe the issue?Overdone
Just to clarify... jQuery has not deprecated using return false in your click handlers? This is Chrome complaining about a snippet of code found inside the jQuery library?Proverbs
Indeed. Chrome has deprecated event.returnValue which only existed for backwards compatibility with IEGeorgettegeorgi
I got the same error message by merely having console.log(x), where x was mouseEvent (onclick). Chrome 33.0.1750.154. I'd consider it's a bug on Chrome's side by triggering the warning too loosely.Northeastward
@Northeastward It is not a bug on Chrome's side. When you use jQuery, Chrome loads the jQuery library and parses it exactly like it would for a script you supplied. If you include jQuery, it will see that event.returnValue is used, and (correctly) throw the warning.Decimate
@kennycoc If jQuery actually had event.returnValue, then it indeed was jQuery's fault. But getting this warning with console.log(mouseEvent) definitely is a bug, as it very effectively disturbs debugging.Northeastward
Sorry, I guess I misunderstood what you were sayingDecimate
C
23

Just for other's reference, I just received this and found it was due to AngularJS. It's for backwards compatibility:

if (!event.preventDefault) {
    event.preventDefault = function() {
        event.returnValue = false; //ie
    };
}
Cornejo answered 19/11, 2013 at 18:19 Comment(3)
I'm getting the error in a bare bones site with no angular being used or referenced - possibly indirectly referenced, but I doubt it.Denigrate
@B.ClayShannon: It's not an error, it's a warning. There's a big difference, especially in our context. You can safely ignore it.Panoply
@B.ClayShannon If you include it at all, Chrome will parse it exactly the same as if it was a script you supplied, and (correctly) throw the warning.Decimate
K
20

If you using Bootstrap:

The current version of Bootstrap (3.0.2) (with jQuery 1.10.2 & Chrome) seems to generate this warning as well.

(It does so on Twitter too, BTW.)

Update

The current version of Bootstrap (3.1.0) no longer seems to generate this warning.

Kislev answered 20/11, 2013 at 14:33 Comment(0)
G
19

That's your jQuery API problem, not your script. There is not much to worry about.

Godhood answered 18/11, 2013 at 10:17 Comment(0)
S
6

This is a warning related to the fact that most JavaScript frameworks (jQuery, Angular, YUI, Bootstrap...) offer backward support for old-nasty-most-hated Internet Explorer starting from IE8 down to IE6 :/

One day that backward compatibility support will be dropped (for IE8/7/6 since IE9 deals with it), and you will no more see this warning (and other IEish bugs)..

It's a question of time (now IE8 has 10% worldwide share, once it reaches 1% it is DEAD), meanwhile, just ignore the warning and stay zen :)

Silvern answered 8/1, 2014 at 12:5 Comment(1)
jQuery 2.x.x only supports IE9 and up. If you want IE8 support in jQuery you need to use version 1.x.x.Village
V
3

I saw this warning on many websites. Also, I saw that YUI 3 library also gives the same warning. It's a warning generated from the library (whether is it jQuery or YUI).

Vedanta answered 27/11, 2013 at 17:25 Comment(0)
M
3

I found that using the latest version will fix this problem:
http://code.jquery.com/jquery-git.js

Mckown answered 5/1, 2014 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.