Office.js dialog API and multiple displays with high DPI

时光总嘲笑我的痴心妄想 提交于 2019-12-07 09:20:26

Thank you Benoit. Yes this is an issue we are aware of and are currently following up.

Could you try using the Dialog helper in OfficeHelpers.js. It's included in v0.5.0 located here (https://unpkg.com/@microsoft/office-js-helpers@0.5.0/dist/office.helpers.js).

The dialog helper allows specifying width and height in pixels as opposed to percentages and we internally calculate the percentage and make the DialogAPI call.

At the moment, it should detect the available space and should create your dialog with the size that you specify. That said, the Dialog takes the size of the window where it was spawned. Hence if you had two monitors one 4k and one being 1280x720 and you spawed a 1920x1080 dialog, it would look massive and wouldn't shrink to fit. That is a limitation currently.

Let me know if you face any issues. Here's the sample code:

(function () {
    $(document).ready(function () {
        Office.initialize = function () {
            // specify the HTTPS url and width and height in pixels.
            // the fourth parameter is to switch to using Microsoft Teams Dialog.

            var dialog = new OfficeHelpers.Dialog('<dialog url>', 1024, 768);
            dialog.result.then(function (value) {
                console.log(value);
            }).catch(function (error) {
                OfficeHelpers.Utilities.log(error);
            });            
        }
    });
})();

// Some where in the Dialog
OfficeHelpers.Dialog.close({
    a: 1,
    alpha: 2,
    'meao': 'cat',
    b: {
        a: 1,
        alpha: 2,
        'meao': 'cat',
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!