Search code examples
javascriptyandex-maps

How to notify iframe in the parent window that all the scripts of yandex map has been loaded?


There is a cross-window iframe, which contains a link to index.php from another server, which, in turn, has a Yandex maps api script (see below). How to make sure that this script chain is fully loaded? I'm trying the following way:

 <script>
            function loaded() {
                window.parent.postMessage('loaded', '*');
            }
        </script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" type="text/javascript"></script>
        <script src="https://api-maps.yandex.ru/2.1/?apikey=bla-bla-bla&lang=ru_RU" type="text/javascript" onload="loaded()"></script>
The message arrives, but the map is not displayed. Which, in my opinion, means incomplete loading of scripts.

Chain of yandex map scripts


Solution

  • Subscribe to ymaps.ready(). https://tech.yandex.com/maps/jsapi/doc/2.1/ref/reference/ready-docpage/

    ymaps.ready(() => notify())