Skip to Content
Menú
This question has been flagged
1 Respondre
2461 Vistes

Hi, I am developing a custom module to create several pages on a website. Does anyone know how to load a js file for each page? I ask that because If you load on web.assets.frontend 1 file this is executed every time you navigate on every page.

Avatar
Descartar
Best Answer

Hi,

One thing you could do is check window.location.href == 'the page url' and then write the functions required for the page, or if there’s a specific class to identify the page, you can find it using jQuery and then write the code inside that.

if($(‘identifier)) {
    function
}

Or you can add the script in the XML so that it only loads when the specific page loads.

Regards

Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
d’oct. 18
4011
2
de des. 22
6622
5
de gen. 22
12322
1
d’ag. 16
5617
1
de maig 25
8862