【问题标题】:How to get Dropbox chooser working as a Sharepoint 2010 Visual Webpart如何让 Dropbox 选择器作为 Sharepoint 2010 Visual Webpart 工作
【发布时间】:2013-12-09 00:03:45
【问题描述】:

我在一个 SP2010 可视 webpart 中有下面的 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>

【问题讨论】:

    标签: javascript internet-explorer sharepoint-2010 dropbox dropbox-api


    【解决方案1】:

    我很惊讶您的第一个示例在 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); }
        });
    }
    

    【讨论】:

    • 感谢 smarx,您的示例运行良好。我还发现我的第一个示例不起作用,因为我的 Sharepoint Masterpages 有一个脚本可以将其转换为使用 IE8 标准。
    猜你喜欢
    • 2012-07-26
    • 2011-03-26
    • 2013-06-07
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    相关资源
    最近更新 更多