E
E
Evgeniy2019-12-27 14:41:14
JavaScript
Evgeniy, 2019-12-27 14:41:14

How to run different js code on different pages of the site?

Good afternoon everyone.
Please help me solve this problem.

There is an online store on cms MODX REVO - You need to run js code 1
in the /catalog/ section (this will be a pop-up window with a test), on all categories, subcategories, product cards that have /catalog/ in the url - And js code should be run on the whole site, except for the /catalog/ section . and write like:





if (window.location.pathname.indexOf('/catalog/') >= 0)) {
  return functionone();
}
else {
 return functiontwo();
}


Or assign a variable to functions ..
In general, sorry for the blood from my eyes, and please help, I just started learning js

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim, 2020-01-09
@Zheleznov

I don’t know how to sew this inside the JS itself, but you can work out this or that scenario within the framework of a document or template:

выводим если шаблон не равен 12]] 

выводим если ID документа равен 1 или 2 или 3]]

You can include separate scripts in these constructions, which will be executed on the necessary pages.

S
sashabeep, 2019-12-27
@sashabeep

In MODX revo, you can always have templates that define the output of things like:
Here in them and write this script of yours. It makes no sense to study location. Because with one simple action, /catalog/ is renamed to /product/, but this does not change its essence. But your script will stop working

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question