تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
2229 أدوات العرض

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
أكتوبر 18
3738
2
ديسمبر 22
6253
5
يناير 22
11876
1
أغسطس 16
5236
1
مايو 25
8427