R
R
Roman Ismailov2017-02-17 11:33:43
JavaScript
Roman Ismailov, 2017-02-17 11:33:43

Display map on page when needed?

Hello Tosturians!
This is the problem, it’s not the first time I’ve encountered it and I don’t know how to solve it correctly: there are maps on the site (several, on different pages), their initialization is written in the general script, when I open a page that does not have a container for some kind of map, it gives an error in the console that it was not possible to do this or that action.
There is a suspicion that beyond the moment where the error is thrown, the script does not execute, how to make it determine whether there is a block on the page and has already initialized it, is this or that block on the page?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Goncharov, 2017-02-17
@Benny_Lilom

if($('#MAPCONTAINER').length){
  //инициализируем карту
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question