简体   繁体   English

在流星中加载Dropbox dropin.js脚本

[英]Loading Dropbox dropin.js script in Meteor

I need to load this script in a Meteor project: <script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="my-api-key"></script> 我需要在Meteor项目中加载此脚本: <script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="my-api-key"></script>

I first tried to do a $('head').append('<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="my-api-key"></script>') on Template.Image.onRendered, but the problem is that the library loads every time the template is rendered, and gives this error: dropins.js included more than once 我首先尝试做一个$('head').append('<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="my-api-key"></script>') ,但问题在于该库在每次渲染模板时都会加载,并出现以下错误: dropins.js included more than once

I've also looked at the wait-on-lib package, https://github.com/DerMambo/wait-on-lib , but I'm not able to pass the data-app-key or id to the Router waiton function. 我还查看了wait-on-lib软件包https://github.com/DerMambo/wait-on-lib ,但是我无法将data-app-key或id传递给Router waiton功能。

Do you have any suggestions on how to load this script? 您对如何加载此脚本有任何建议吗?

I've never used dropbox sdk, but maybe this help you or give some idea for that. 我从未使用过dropbox sdk,但这也许对您有所帮助或为此提供一些想法。

if(window.Dropbox){
    // Nice, is already loaded
}
else {
    $("head")
        .append('<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="your-api-key"></script>');
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://www.dropbox.com/static/api/2/dropins.js';
    head.appendChild(script);
    script.onload = function(){
        //whatever, I Want It All!
    };
}

You can add this on your Template.template_name.onCreated code block. 您可以将其添加到Template.template_name.onCreated代码块上。

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

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