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/