跳至內容
選單
此問題已被標幟
1 回覆
2422 瀏覽次數

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.

頭像
捨棄
最佳答案

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

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
1
10月 18
3974
2
12月 22
6615
5
1月 22
12300
1
8月 16
5595
1
5月 25
8847