简体   繁体   English

将远程库 (API 4.5 Mapy.cz) 包含到 Google Chrome 扩展程序中

[英]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.我正在尝试制作小 chrome 扩展(弹出窗口),我需要连接到远程 API。 This is, what I would use, if it is a standard web page:如果它是标准的 web 页面,我会使用这个:

<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.链接 API 加载程序很好并且可以工作。 Thanks to @serg.感谢@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. Object 加载程序已定义,一切正常。 Loader should load the whole API either object SMap.加载程序应加载整个 API 或 object SMap。 But SMap is undefined.但是 SMap 是未定义的。 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:如果您需要向此远程 API 发出 ajax 请求,则需要在清单的权限中列出 API 域:

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

Finally I ask developer from Mapy.cz and they gave the solution.最后我问了 Mapy.cz 的开发人员,他们给出了解决方案。 Instead of using Loader.load() which cause including additional script and async load - use this way:而不是使用 Loader.load() 导致包括额外的脚本和异步加载 - 使用这种方式:

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

Final Example of usage最终使用示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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