Help with switching to the back of card

I got this code to switch to the back of the card from here.

	if (typeof pycmd !== "undefined") {
		pycmd("ans")
	} else if (typeof study !== "undefined") {
		study.drawAnswer()
	} else if (typeof AnkiDroidJS !== "undefined") {
		showAnswer()
	} else if (window.anki && window.sendMessage2) {
		window.sendMessage2("ankitap", "midCenter")
	}

It seems to be working only in Anki Desktop (I have tried on Anki Desktop, AnkiWeb and AnkiDroid)
Could anybody help me to switch to the back of the card in the other versions of Anki?

The AnkiDroid part might be broken due to this: [BUG]: globalThis.AnkiDroidJS is undefined · Issue #16357 · ankidroid/Anki-Android · GitHub
You can replace the typeof AnkiDroidJS !== "undefined" part with just window.showAnswer to fix the issue.

1 Like

This will work for all platforms, right? (I can’t test on AnkiMobile, but wish to be aware which platform this might not work on, so that I can add a disclaimer when sharing the deck)

I can only guarantee this will work on the computer Anki and AnkiDroid. AnkiMobile doesn’t have a reliable way as far as I know. The method shared in the linked thread is probably broken now. See disclaimer there:

1 Like

I just need to call window.showAnswer, right? I tested it on a basic template and that isn’t changing to the back of the card.

{{Front}}
<script>
window.ShowAnswer
</script>

On computer Anki: pycmd('ans').
On AnkiDroid: window.showAnswer().

1 Like

And for AnkiWeb? The initial one did not work.

The study.drawAnswer() part was probably for AnkiWeb, but I think it’s now broken.

1 Like

I could only get this to work for computer, not AnkiDroid.

This is the correct code:

<script>
window.showAnswer()
</script>

Yeah, I used this for AnkiDroid and it didn’t work.

Weird. Worked for me in a basic note type.