One Drive JS File Picker : error in window's o

2019-05-26 10:33发布

问题:

I am trying to implement the One Drive File Picker as instructed

The One Drive window opens fine and you select a file but then doesn't return to my site, i get a continuous waiting spinner.

If i look in the Chrome console I am seeing multiple lines of the following

[OneDriveSDK] error in window's opener, pop up will close. Array[1]

And then at the end

Uncaught RangeError: Maximum call stack size exceeded OneDrive.js:2

My Code

<button id="onedrive">Open from OneDrive</button>

<script type="text/javascript" src="https://js.live.net/v7.0/OneDrive.js"></script>

...

$(document).ready(function() {
    $("#onedrive").click(function () {
        console.log("One Drive Clicked");
        var odOptions = {
            clientId: "########",
            action: "share",
            multiSelect: false,
            openInNewWindow: true,
            advanced: {},
            success: function (files) {
                console.log(files);
            },
            cancel: function (c) {
                console.log(c);
            },
            error: function (e) {
                console.log(e);
                alert(e);
            }
        };
        OneDrive.open(odOptions);
    });
});

回答1:

There was a form behind the button which was causing the form to submit, and open the OneDrive Window at the same time meaning it couldn't return.

Button has now been changed to an input type="button"

<input type="button" id="onedrive" name="onedrive" value="Choose from OneDrive">