[英]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.