# Javascript not re-running between different pages

**URL:** https://meta.discourse.org/t/javascript-not-re-running-between-different-pages/170999
**Category:** Support
**Created:** [November 23, 2020, 10:16am UTC](https://meta.discourse.org/t/javascript-not-re-running-between-different-pages/170999 "2020-11-23T10:16:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![welburn](https://avatars.discourse-cdn.com/v4/letter/w/f0a364/32.png) [@welburn](https://meta.discourse.org/u/welburn)
#### Post date: [November 23, 2020, 10:16am UTC](https://meta.discourse.org/t/javascript-not-re-running-between-different-pages/170999/1 "2020-11-23T10:16:00Z")

</div>

Hi All,

I developed a theme component that rotates using the swiper.js library. In the head tag of my component I get the swiper js/css files from the CDN and also declare the element on the page as a swiper inside a window.ready function.

The issue I’m running into is that it rotates fine when you directly navigate to that page, but if you click on any link on the Discourse site that takes you to that page, the first slide is loaded but it is a static image and this component will not animate (rotate) until you refresh the page.

I have a suspicion this is due to the fact that the javascript is not re-running when navigating between pages in Discourse, instead content is just generated on different pages. Is this how Discourse works and, if so, is there a workaround to this?

---

<div class="post-metadata">

### Author: ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)
#### Post date: [November 23, 2020, 12:16pm UTC](https://meta.discourse.org/t/javascript-not-re-running-between-different-pages/170999/2 "2020-11-23T12:16:00Z")

</div>

You need to put this code in a theme component:

```plaintext
<script type="text/discourse-plugin" version="0.8">
    api.onPageChange(() =>{
        callYourFunctionHere();
    });
</script>

```

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [December 23, 2020, 12:16pm UTC](https://meta.discourse.org/t/javascript-not-re-running-between-different-pages/170999/3 "2020-12-23T12:16:18Z")

</div>

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