在ADAL.js中嵌入PowerBI仪表板时,需要设置IFrame的目标原始地址以确保安全性。以下是示例代码:
var authContext = new AuthenticationContext({
instance: 'https://login.microsoftonline.com/',
tenant: 'yourtenant.onmicrosoft.com',
clientId: 'your_client_id',
});
authContext.handleWindowCallback();
authContext.acquireToken(
'https://analysis.windows.net/powerbi/api',
function (error, token) {
var iframe = document.createElement('iframe');
iframe.src = 'https://app.powerbi.com/reportEmbed?reportId=your_report_id';
iframe.height = '600px';
iframe.width = '800px';
iframe.frameBorder = '0';
iframe.setAttribute('sandbox', 'allow-scripts allow-forms allow-same-origin allow-popups');
iframe.setAttribute('style', 'border: 1px solid #ddd;');
iframe.addEventListener('load', function() {
console.log('IFrame loaded!');
});
document.getElementById('dashboard__container').appendChild(iframe);
}
);
在该代码示例中,iframe
元素被创建并包含了PowerBI仪表板的URL。为了保证安全性,设置了sandbox
属性为allow-scripts allow-forms allow-same-origin allow-popups
。此外,load
事件监听器被添加,以确保IFrame成功加载。