# How can I run JavaScript on a specific side only?

**URL:** <https://forums.ankiweb.net/t/how-can-i-run-javascript-on-a-specific-side-only/43328>\
**Category:** Help\
**Created:** [April 7, 2024, 5:12pm UTC](https://forums.ankiweb.net/t/how-can-i-run-javascript-on-a-specific-side-only/43328 "2024-04-07T17:12:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![armadillo](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@armadillo](https://forums.ankiweb.net/u/armadillo)\
**Post date:** [April 7, 2024, 5:12pm UTC](https://forums.ankiweb.net/t/how-can-i-run-javascript-on-a-specific-side-only/43328/1 "2024-04-07T17:12:45Z")

</div>

I’ve created a JavaScript timer and placed it in the front template of the card to do some tweaks. However, when I test it during review, it continues to run even when I flip to the back side (this issue doesn’t occur on AnkiDroid), it seems that Anki runs the scripts once in the beginning of the review session only.

I would like it to run only on the front sides and not persist to the back side (i don’t want communication between scripts of the front and the back templates)

Thank you!

---

<div class="post-metadata">

**Author:** ![armadillo](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@armadillo](https://forums.ankiweb.net/u/armadillo)\
**Post date:** [April 8, 2024, 7:23am UTC](https://forums.ankiweb.net/t/how-can-i-run-javascript-on-a-specific-side-only/43328/2 "2024-04-08T07:23:17Z")

</div>

Any reponse ?

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [April 8, 2024, 8:51am UTC](https://forums.ankiweb.net/t/how-can-i-run-javascript-on-a-specific-side-only/43328/3 "2024-04-08T08:51:27Z")

</div>

The front & back sides of a card are considered a single web page, so they share state.

You can work around the issue by adding some unique HTML to the front/back side then checking for it and deciding whether to run/stop the timer accordingly.

---

<div class="post-metadata">

**Author:** ![armadillo](https://avatars.discourse-cdn.com/v4/letter/a/e19b73/32.png) [@armadillo](https://forums.ankiweb.net/u/armadillo)\
**Post date:** [April 8, 2024, 11:12am UTC](https://forums.ankiweb.net/t/how-can-i-run-javascript-on-a-specific-side-only/43328/4 "2024-04-08T11:12:28Z")

</div>

Thank you abdo!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [May 8, 2024, 11:13am UTC](https://forums.ankiweb.net/t/how-can-i-run-javascript-on-a-specific-side-only/43328/5 "2024-05-08T11:13:16Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
