Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
1 Balas
2237 Tampilan

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
Buang
Jawaban Terbai

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
Buang
Post Terkait Replies Tampilan Aktivitas
1
Okt 18
3744
2
Des 22
6262
5
Jan 22
11882
1
Agu 16
5239
1
Mei 25
8439