# Trigger javascript on clicking any page link, but before the page content loads?

**URL:** <https://meta.discourse.org/t/trigger-javascript-on-clicking-any-page-link-but-before-the-page-content-loads/167970>\
**Category:** Development\
**Created:** [October 22, 2020, 3:13pm UTC](https://meta.discourse.org/t/trigger-javascript-on-clicking-any-page-link-but-before-the-page-content-loads/167970 "2020-10-22T15:13:01Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![merefield](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/merefield/32/176214_2.png) [@merefield](https://meta.discourse.org/u/merefield)\
**Post date:** [November 4, 2024, 12:16pm UTC](https://meta.discourse.org/t/trigger-javascript-on-clicking-any-page-link-but-before-the-page-content-loads/167970/8 "2024-11-04T12:16:37Z")

</div>

Happy to be explicit as the code is open source:

> <https://github.com/merefield/discourse-tc-house-ads-livewrapped/blob/ce2bc2a3d7d4ef8ad29f48295c5c9b37403dbeb5/javascripts/discourse/components/livewrapped-ad.gjs#L43>

I’m working with a third party ad provider and they have an ad page reset function in javascript that needs to be run before the new page’s ads are triggered.

any improvement is welcome and I’ve already realised this on the Topic List with Johani’s code. (in an open PR).

But this left the Topic … I will try your suggestion next and adopt it in both instances if that improves things further.

---

_[View the full topic](https://meta.discourse.org/t/trigger-javascript-on-clicking-any-page-link-but-before-the-page-content-loads/167970)._
