Search…

X3 Photo Gallery Support Forums

Search…
 
alderim
Experienced
Topic Author
Posts: 75
Joined: 27 Jun 2007, 05:49

custom javascript only works on page refresh

10 Mar 2020, 08:35

Hi,

I would like to create a small question form that the values of radio buttons are added in the background and a result is given in the end.

I'm not a programmer, the code is correspondingly brutforce cumbersome, but it works (for me) ;)

BUT only after I refresh the page with the form. If I come from another place and navigate to the page with the form, it won't work until I refresh the site.

Any hint how i can avoid this?

Thx!
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: custom javascript only works on page refresh

10 Mar 2020, 09:51

Hi. That's because X3 is essentially a SPA (single page application) which loads pages with Ajax/XHR and injects the page into the website for faster and smoother navigation. Technically, that also means that your custom Javascript will only execute on initial page load, but not when navigating pages from the menu.

The solution is to use the x3_load_page() function, which triggers on every page load in X3, also after navigating from the menu. For example
Code
function x3_load_page(){
  console.log('Runs after each X3 ajax page load');
}
You would have to add your code inside x3_load_page() function.
 
alderim
Experienced
Topic Author
Posts: 75
Joined: 27 Jun 2007, 05:49

Re: custom javascript only works on page refresh

10 Mar 2020, 11:54

works perfect, THX!