# Using the 'Discourse' javascript class in a hosted forum

**URL:** https://meta.discourse.org/t/using-the-discourse-javascript-class-in-a-hosted-forum/77704
**Category:** Support
**Created:** [January 10, 2018, 10:00pm UTC](https://meta.discourse.org/t/using-the-discourse-javascript-class-in-a-hosted-forum/77704 "2018-01-10T22:00:43Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![garrettboatman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/garrettboatman/32/120397_2.png) [@garrettboatman](https://meta.discourse.org/u/garrettboatman)
#### Post date: [January 10, 2018, 10:00pm UTC](https://meta.discourse.org/t/using-the-discourse-javascript-class-in-a-hosted-forum/77704/1 "2018-01-10T22:00:43Z")

</div>

Hi! Developer fairly new to Discourse here.  
I have a hosted forum, so I’m trying to hook into the `Discourse` class via a `<script>` block in `</body> Customization` section of the admin.

I see examples in this forum of application views like `Discourse.ApplicationView`, `Discourse.DiscoveryCategorysView`, and `Discourse.CloakedView`.  
However, none of these are available in the `Discourse` class I see.

The `Discourse` class I see:

 ![23 PM](https://global.discourse-cdn.com/meta/original/3X/8/9/89ed17ce1c91185ca965377f9e188ce1bb9e6670.png)

–

All I’m trying to do is `doSomething()` after a new view gets loaded. Like…

```
Discourse.ApplicationView.reopen({
    didInsertElement: function() {
        this._super();
        doSomething();
    },
    
    pathChanged: function() {
        Ember.run.scheduleOnce('afterRender', this, function() {
            doSomething();
        });
    }.observes('controller.currentPath', 'controller.model')
});

```

But I get `Cannot read property 'reopen' of undefined` because `Discourse.ApplicationView` doesn’t exist.

Any way to access the application view without writing a plugin?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [January 10, 2018, 10:16pm UTC](https://meta.discourse.org/t/using-the-discourse-javascript-class-in-a-hosted-forum/77704/2 "2018-01-10T22:16:20Z")

</div>

You can probably do what you want with the plugin-api. Take a look at this topic: [Using the JS API](https://meta.discourse.org/t/using-the-pluginapi-in-site-customizations/41281) and this file: [https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6](https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6).

Depending on what you’re trying to do, the `modifyClass` or `onPageChange` functions could be useful.

---

<div class="post-metadata">

### Author: ![garrettboatman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/garrettboatman/32/120397_2.png) [@garrettboatman](https://meta.discourse.org/u/garrettboatman)
#### Post date: [January 11, 2018, 1:03am UTC](https://meta.discourse.org/t/using-the-discourse-javascript-class-in-a-hosted-forum/77704/3 "2018-01-11T01:03:42Z")

</div>

@simon - that’s exactly what I needed, thank you!

For future devs:

```
<script type="text/discourse-plugin" version="0.1">
  api.onPageChange((url, title) => {
    doSomething();
  });
</script>

```

^^ in the `</head>` Customize tab.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [June 8, 2024, 12:43pm UTC](https://meta.discourse.org/t/using-the-discourse-javascript-class-in-a-hosted-forum/77704/4 "2024-06-08T12:43:37Z")

</div>

This topic was automatically closed after 2340 days. New replies are no longer allowed.
