AnkiDroid and JavaScript

463 views
Skip to first unread message

Thomas Kahn

unread,
Jan 3, 2013, 10:14:42 AM1/3/13
to anki-a...@googlegroups.com
Hey Nicolas,

does the new version of AnkiDroid support JavaScript?

Best regards and good luck with your project!

Thomas

Houssam Salem

unread,
Jan 3, 2013, 3:25:45 PM1/3/13
to anki-a...@googlegroups.com, thomas....@googlemail.com
It does. You need to use the desktop client to put the scripts in your templates. AnkiDroid doesn't have a template editor.

Houssam Salem

unread,
Jan 5, 2013, 10:25:07 PM1/5/13
to anki-a...@googlegroups.com, thomas....@googlemail.com, qtf...@gmail.com
Both Anki and AnkiDroid use a standard Webkit implementation, including the javascript engine that comes along with it (JavaScriptCore, I think). So they're actually very capable. I once put jQuery in a deck (but this was in the previous release).

Alerts aren't enabled by default in the Android WebView, so that's why that doesn't work. Your other code snippet does actually work in AnkiDroid though. I noticed on the desktop client that it works in the card editor but not the reviewer. It probably has something to do with using Strict HTML, but I don't know for sure.

On Sunday, January 6, 2013 4:38:02 AM UTC+11, qtf...@gmail.com wrote:


On Thursday, January 3, 2013 9:25:45 PM UTC+1, Houssam Salem wrote:
It does. [...]
No.

<script>
   alert( "hello world." );
</script>

Did not work for me.

Neither did
<script>
   if( document.images.length ) document.write( document.images[ 0 ].clientHeight );
</script>


I don't know whether the interpreter is self-made or "ready-made", but the implementation seems incomplete. Would be great to use it, e.g. to re-size images when a card is turned. Then, one could zoom in freely (which is not possible w/ max-width/max-height.) Also: cookies. But cookies don't even work in the desktop version. This way one could, for example, activate hints for new sessions and turn them off when advanced. Or access to parameters like how advanced a card is, etc. pp. would be awesome. Possibilities would be endless if Elmes and the AnkiDroid devs would implement a functional javascript engine. Though I don't know if it is worth the hussle as most people will probably not be bothering with javascript. On the other hand, one could always use pre-made code snippets...
Reply all
Reply to author
Forward
0 new messages