简体   繁体   中英

Include remoted Library (API 4.5 Mapy.cz) to Google Chrome Extension

I am confused. I'am trying to make little chrome extension (popup) and I need connect to remoted API. This is, what I would use, if it is a standard web page:

<script type="text/javascript" src="http://api4.mapy.cz/loader.js"></script>
<script type="text/javascript">Loader.load();</script>

I experimented with including new element script to head (not works for me). But I couldn't believe, there is no easier way...

Please, show me the best way.


EDIT:

Linking the API loader is fine and works. Thanks to @serg. So, my code of popup looks like this:

<script type="text/javascript" src="http://api4.mapy.cz/loader.js"></script>
<script type="text/javascript">
    Loader.load();
    var center = SMap.Coords.fromWGS84(16.61574, 49.20315);
</script>

Object Loader is defined and it is OK. Loader should load the whole API either object SMap. But SMap is undefined. What next?

If you need to make ajax requests to this remote API, you need to list API domain in the permissions in your manifest:

{
  "permissions": [
    "http://api4.mapy.cz/"
  ],
}

Finally I ask developer from Mapy.cz and they gave the solution. Instead of using Loader.load() which cause including additional script and async load - use this way:

Loader.async = true;
Loader.load(null, null, function(){
    alert(123); // it works...
    // custom code calling objects etc. from API
    // ...
});

Final Example of usage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM