Javascript Compatibility

Is there a way to know how many javascript commands are really compatible with Anki?

Is there any technical term to identify this?

I’m asking, because I decided to learn javascript (I love Python) to customize my cards, but not all commands work correctly, requiring some adaptations.

Anki is not the most basic web environment you can get, so if you are learning JS you may be surprised in the result; but this doesn’t mean there is a fundamental incompatibility between JS and Anki.

1 Like

Supported HTML/CSS/JS features depend on the client/OS you’re running Anki on. See for example:

If you know the browser, https://caniuse.com/ can serve as a lookup table.

AFAIK there’s no summary of currently used browser engines for all Anki clients. It’s a good idea though, and doesn’t seem that hard to implement.


Personally, I was positively surprised by Anki’s potiential as a JS learning environment. Working on things you actually make use of tends to be a very efficient way to learn new programming languages.

2 Likes

IIRC, Anki Desktop (through Qt Webviews) relies on chromium’s engines, that is, Blink (and V8 for the JS engine), AnkiWeb uses whatever you use, AnkiMobile uses safari’s engine (webkit — blink is a fork of webkit, so thy should behave similarly).

1 Like

I agree having a motivating usage can is useful when learning a language, but at the same time coding JS in Anki is probably less practical that writing a “regular” JS script that can be tested in IDE-integrated web environment, for a tighter feedback loop.

1 Like

@cjdduarte also take care to use vanilla JavaScript in your templates.

StackOverflow is riddled with jQuery answers, but nowadays, there’s no real benefit to using this library.

You can easily spot jQuery by its $-prefixed functions.

3 Likes

I learned new things here that I didn’t know.

The reason to use javascript is not to depend on an addon for simple things.
More dynamic cards.
And being able to use on Mobile.

In general, you should see JS as an “extension” of HTML and CSS, in the sense that it complements these while being at the same level. Anki add-ons, on the other hand, are more though as ways to modify Anki’s behavior.