[英]SSRS - Javascript Report load event
我將報告嵌入到 iframe 中(使用 .NET ReportingServices 獲取報告)
我想在加載報告后啟動一個 Javascript 函數。
我試過了:
window.addEventListener("load", ...)
但是由於報表結果是用 Javascript 加載的,所以在報表被有效加載之前觸發了window.load
。
是否有一些 Javascript 函數可以讓我處理報告負載? 像:
the_report.loaded(function () {
alert(document.height);
});
順便說一下,目的是獲得最終渲染的文檔高度。
這正是我最終得到的(iframe 方面)
/* This will run only when all ReportingService JS is loaded */
Sys.Application.add_load(function () {
/* Let's consider the report is already loaded */
loaded = true;
/* The function to call when the report is loaded */
var onLoad = function () {
alert(document.body.scrollHeight);
/* Set the report loaded */
loaded = true;
};
/* The report instance */
var viewerReference = $find("ReportViewer1");
/* The function that will be looped over to check if the report is loaded */
check_load = function () {
var loading = viewerReference.get_isLoading();
if (loading) {
/* It's loading so we set the flag to false */
loaded = false;
} else {
if (!loaded) {
/* Trigger the function if it is not considere loaded yet */
onLoad();
}
}
/* Recall ourselves every 100 miliseconds */
setTimeout(check_load, 100);
}
/* Run the looping function the first time */
check_load();
})
Javascript 支持充其量是最少的。 遺憾的是,這些控制措施在大多數方面仍與時俱進。 您可以在此處找到公開和記錄的內容:
http://msdn.microsoft.com/en-us/library/dd756405(VS.100).aspx
幸運的是,您可以調用 get_isLoading() 函數:
http://msdn.microsoft.com/en-us/library/dd756413(v=vs.100).aspx
嘗試這樣的事情:
(function() {
var onLoad = function() {
// Do something...
};
var viewerReference = $find("ReportViewer1");
setTimeout(function() {
var loading = viewerReference.get_isLoading();
if (!loading) onLoad();
},100);
})();
基於 Pierre 的解決方案,我最終得到了這個。 (簡化為只在加載一次之前調用它,因為它似乎在每次加載后運行)
注意:我的報告配置是 SizeToReportContent="true" AsyncRendering="false",所以這可能是我可以簡化它的部分原因。
Sys.Application.add_load(function () { var viewerReference = $find("ReportViewer1"); check_load = function () { if (viewerReference.get_isLoading()) { setTimeout(check_load, 100); } else { window.parent.ReportFrameLoaded(); } } check_load(); });
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.