如何在父窗口中通知iframe yandex映射的所有脚本均已加载?

问题描述

一个跨窗口iframe,其中包含从另一台服务器到index.PHP链接,而另一台服务器又具有Yandex maps api脚本(请参见下文)。如何确保此脚本链已完全加载?我正在尝试以下方式:

 <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>
消息到达,但未显示地图。我认为,这意味着脚本加载不完整。

Chain of yandex map scripts

解决方法

订阅ymaps.ready()https://tech.yandex.com/maps/jsapi/doc/2.1/ref/reference/ready-docpage/

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