javascript - 如何使用脚本加载器加载 LinkedIn Javascript API 库?

标签 javascript linkedin

LinkedIn Api 建议您像这样加载他们的 javascript 库:

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: your_api_key_goes_here
</script>

我想知道如何使用脚本加载器(例如 RequireJS 或 LABJS)加载它。该库似乎从脚本标签中提取了 api key 。在我看来,这似乎是一种非常奇怪的做法!

我更喜欢使用脚本加载器加载库,但似乎无法找到如何在不使用建议方法的情况下插入 api_key。

The official instructions are here

有人有什么想法吗?

最佳答案

发件人:https://developer.linkedin.com/documents/general-methods

异步加载

为避免在页面中遇到竞争条件,您可以异步加载框架。

如果您的页面使用 JQuery,则以下代码将起作用:

$(document).ready(function() {
    $.getScript("http://platform.linkedin.com/in.js?async=true", function success() {
        IN.init({
            onLoad: "myOnloadFunction"
        });
    });
});

否则,你需要这样的东西:

<script type="text/javascript" src="http://platform.linkedin.com/in.js?async=true"></script>
<script type="text/javascript">
    IN.init({
        onLoad: "myOnloadFunction"
        // any other parameters you'd normally put beneath the script element would be here
    });
</script>

关于javascript - 如何使用脚本加载器加载 LinkedIn Javascript API 库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9071249/

相关文章:

javascript - 在 Windows 8 应用程序中本地保存数据的最佳方法

javascript - html,js 中的 css 编辑器

javascript - LinkedIn 用他们的 JS SDK 做了什么魔术?存在脚本主体和 src,加上奇怪格式的主体

javascript - 使用 KineticJS 在舞台上动态添加圆圈

javascript - 行选择行为 sap.ui.table.Table

javascript - 需要深入了解这一小段 HTML 和 Javascript

arrays - 算法 - LinkedIn Coding Round

iphone - LinkedIn 菜单 iPhone 应用程序

java - 如何在android中获取Linkedin个人资料的连接

php - 将 PHP 生成的 JS 变量发送到 Google map 的 JS 函数