# Script executed after system.nav.swapWindow

**URL:** <https://forum.inductiveautomation.com/t/script-executed-after-system-nav-swapwindow/96069>\
**Category:** Ignition\
**Tags:** ignition81, vision\
**Created:** [September 17, 2024, 3:14pm UTC](https://forum.inductiveautomation.com/t/script-executed-after-system-nav-swapwindow/96069 "2024-09-17T15:14:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephane\_Boneff](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@Stephane\_Boneff](https://forum.inductiveautomation.com/u/Stephane_Boneff)\
**Post date:** [September 17, 2024, 3:14pm UTC](https://forum.inductiveautomation.com/t/script-executed-after-system-nav-swapwindow/96069/1 "2024-09-17T15:14:37Z")

</div>

Hello,

After upgrade to 8.1.39, an App I didn't wrotten but I maintain has a strange behavior :  
On only one view, system.nav.swapWindow(xxx) displays the good view but the script on the from view is still executed.  
The script is linked to a button (actionPerformed)

```python
if blabla :
[...]
   system.nav.swapWindow(xxx) 
   print "why this line is printed ?"

```

In this example, the line print is executed (and the end of the script too that is finally crashing).

I had to use that as work around :

```python
   system.nav.swapWindow(xxx) 
   sys.exit()

```

Anyone has some idea ?

Thanks !

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 17, 2024, 3:33pm UTC](https://forum.inductiveautomation.com/t/script-executed-after-system-nav-swapwindow/96069/2 "2024-09-17T15:33:53Z")

</div>

> [@Stephane\_Boneff](#):
>
> `print "why this line is printed ?"`

Why would you expect the script to terminate after calling a system function?

If it's necessary to terminate a script at a given point, put it in a library script or custom method. Then, `return` can be used to stop the code at any point.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 17, 2024, 4:02pm UTC](https://forum.inductiveautomation.com/t/script-executed-after-system-nav-swapwindow/96069/3 "2024-09-17T16:02:25Z")

</div>

> [@Stephane\_Boneff](#):
>
> Anyone has some idea ?

Do not use `sys.exit()` for starters.

What is the script from the line that is "crashing".

The solution is, that you should not execute any script following navigation away from a window that expects components on the window you are moving away from to still exist. The original author of the script set you up for failure there. If that part of the script needs to execute, then move it prior to the navigation.
