繁体   English   中英

如何使Dropbox选择器作为Sharepoint 2010 Visual Webpart工作

[英]How to get Dropbox chooser working as a Sharepoint 2010 Visual Webpart

我在SP2010可视化Web部件中具有以下javascript代码,该部件可在Google Chrome浏览器中使用,但不能在IE9中使用。 令人担忧的是,Dropbox选择器网站说addEventListener不适用于IE8或更低版本。

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DropboxControlUserControl.ascx.cs" Inherits="DropBoxWebPart.DropboxControl.DropboxControlUserControl" %>
<script type="text/javascript" src="https://www.dropbox.com/static/api/1/dropins.js" id="dropboxjs" data-app-key="xxxxxxxxxxxxxxx"></script>

<input type="dropbox-chooser" name="selected-file" id="db-chooser"/>
<script type="text/javascript">
   document.getElementById("db-chooser").addEventListener("DbxChooserSuccess",
     function(e) {
         window.open(e.files[0].link)
     }, false);
</script>

我试图使用Dropbox.chooser(options)函数来克服此问题,但是我不确定在哪里放置代码或从中调用函数。 我是否需要从背后的代码中调用它,因为我试图将其放在这样的脚本中,还尝试使用document.getElementById(“ db-chooser”)。on或.attachevent使其无法正常工作。

<script type="text/javascript">
Dropbox.chooser(options);
options = {

        // Required. Called when a user selects an item in the Chooser.
        success: function(files) {
            alert("Here's the file link:" + files[0].link)
        },

        // Optional. Called when the user closes the dialog without selecting a file
        // and does not include any parameters.
        cancel: function() {

        },

        linkType: "preview" or "direct",     

        extensions: ['.pdf', '.doc', '.docx'],            
    };
</script>

我很惊讶您的第一个示例在IE9中不起作用。 对我来说很好。 我稍后再尝试。 编辑 :虽然确实是在IE9模式下的IE10上,但我确实有机会尝试它。代码对我来说很好。)

对于第二个示例,直到将其作为参数传递 ,您才需要定义options (因此,您传递的是一个未定义的变量,然后在以后定义它。)如果您只是放置Dropbox.choose(options); 在您实际定义了该变量之后,我希望它可以工作。

另外,该linkType无效。 选择一个,“预览”或“直接”。 首先,请尝试以下代码:

var options = {
    success: function (files) { alert(files[0].link); }
}
Dropbox.choose(options);

或者,如果您愿意:

Dropbox.choose({
    success: function (files) { alert(files[0].link); }
});

您需要运行该代码以响应用户操作(例如单击链接),以免弹出窗口阻止程序阻止您。 所以像这样:

document.getElementById('mybutton').onclick = function () {
    Dropbox.choose({
        success: function (files) { alert(files[0].link); }
    });
}

暂无
暂无

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

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