# Trigger a script when user is navigating to a page in a tab that's already opened

**URL:** <https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 6, 2023, 1:11pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476 "2023-02-06T13:11:48Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Theodorska](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Theodorska](https://forum.inductiveautomation.com/u/Theodorska)\
**Post date:** [February 6, 2023, 1:11pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/1 "2023-02-06T13:11:48Z")

</div>

Hello,

I want to make a dynamic menu that shows recently visited pages. I want to update a FlexRepeater whenever the user navigates to a new page. I tried using Page StartUp session event. However, this will only work when the user refreshes a page or opens a page in a new tab or window. Is there a way to trigger scripts when the user i navigating between pages in a tab or window that is already opened?

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [February 6, 2023, 2:05pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/2 "2023-02-06T14:05:42Z")

</div>

I'm assuming they are navigating the pages via some sort of button.

Which could be where you place a script. When they click to navigate a page you add it to the list, And the list only stores x number of recent pages. of course, with a method of ordering tossed in.

---

<div class="post-metadata">

**Author:** ![Theodorska](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Theodorska](https://forum.inductiveautomation.com/u/Theodorska)\
**Post date:** [February 6, 2023, 2:10pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/3 "2023-02-06T14:10:35Z")

</div>

That would be possible, but the tool we are developing have too many ways to navigate to different pages. It would be the most efficient if there was a way to develop a trigger that acts when the url changes. This could be done by a timer script and a while loop, but I am trying to avoid having while loops running constantly in the background

---

<div class="post-metadata">

**Author:** ![Theodorska](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Theodorska](https://forum.inductiveautomation.com/u/Theodorska)\
**Post date:** [February 6, 2023, 2:12pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/4 "2023-02-06T14:12:24Z")

</div>

Maybe if I make memory tag that stores the current url and uses a gateway event on tag change to script it...

---

<div class="post-metadata">

**Author:** ![Theodorska](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@Theodorska](https://forum.inductiveautomation.com/u/Theodorska)\
**Post date:** [February 6, 2023, 2:34pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/5 "2023-02-06T14:34:10Z")

</div>

however, I am not able to get the current URL

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [February 6, 2023, 2:36pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/6 "2023-02-06T14:36:23Z")

</div>

I'm not too familiar with perspective. But I don't think it's feasible to monitor the URL. in a tag.

Especially because you can open views without changing the URL just passing it as a keyword argument. And it might be hard to monitor what is open as you may not be closing them.

Also, a gateway script would be no good. It cannot know the URL of a client-side session.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [February 6, 2023, 2:38pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/7 "2023-02-06T14:38:12Z")

</div>

Yeah I was just typing up that response.

You are gonna have to add something at each place you open a page from even if its a custom property you can change and monitor.

Someone may chime in on a better way

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 6, 2023, 2:40pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/8 "2023-02-06T14:40:55Z")

</div>

If you write it to a custom session property, you can trigger off that.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [February 6, 2023, 2:45pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/9 "2023-02-06T14:45:41Z")

</div>

Would he have to write it as each place he opens it? Or would he be able to write it via monitoring it someway more central?

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 6, 2023, 3:27pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/10 "2023-02-06T15:27:47Z")

</div>

He'd have to write it as he opens it. There's no way to directly access a view's URL because you could have multiple URLs to the same view. You can also navigate to views without changing the URL.

---

<div class="post-metadata">

**Author:** ![andrews](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@andrews](https://forum.inductiveautomation.com/u/andrews)\
**Post date:** [February 6, 2023, 9:01pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/11 "2023-02-06T21:01:47Z")

</div>

@JordanCClark thats what I thought. Aligns with my original suggestion, but he didn’t like it.

My only other thought to the OP would be to focus on templates and indirect addressing. Maybe he can condense the many ways they open into some sort of dynamic structure .

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [February 6, 2023, 9:38pm UTC](https://forum.inductiveautomation.com/t/trigger-a-script-when-user-is-navigating-to-a-page-in-a-tab-thats-already-opened/69476/12 "2023-02-06T21:38:21Z")

</div>

The only way to manage something like this requires a piece of UI shared across all pages in the project. We have something like this in our automated testing project, where there is a shared Docked View we use for navigation.

Within the View used for the Docked View, bind some custom property against `page.props.path` (ignore any preview in the Designer as the page path prop behaves differently in the Designer). Now, you just need to place a change script on this custom property and you'll know whenever any open page for the session changes the URL.
