手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

报表组件FineReport在报表中如何调用客户的js

时间:2024-11-18 22:27:06

1、问题描述两种情况:1、报表嵌入在某个页面的iframe框架中,需要在报表模板中获取页面里面定义的方法;2、报表嵌入在某个页面的iframe框架中,需要在报表模板中获取页面中另一个iframe里面的方法。

2、解决方案首先通过js获取方法所在的对象,然后通过方法名调用:情况1中页面对于模板来说是父,因此可以通过parent.window.fnname()调用父页面的方法;情况2中通过父页面获取另一个iframe,再调用其中的方法:parent.window.getElementById("iframename").contentWindow.fnname()。

3、示例前提准备如下page1.html中,通过iframe嵌入了一张report报表及page2.html页面;在page1中定义了方法fun1:<html> <head> <title>page1</title><script type="text/javascript">function fun1(){alert("这是主页面中的方法!");} </script> </head> <body><p>这是page1</p><iframe src="/WebReport/page2.html" name="page2" id="page2" ></iframe><iframe src="/WebReport/ReportServer?reportlet=report.cpt" name="report" scrolling="auto"></iframe> </body></html>

4、其中page2.html中也定义了一个方法fu艘绒庳焰n2:<html> <head> <title&爿讥旌护gt;page2</title> <script type="text/javascript">function fun2(){var name = alert("这是嵌在另一个iframe中页面里的方法!")} </script> </head> <body> <P>这是page2!</p> </body></html>

5、在模板中调用客户自己的js方法如在report.cpt模板的参数界面提交按钮点击事件中,获取页面page1及page2中的方法,js如下:var page1 = parent.window;page1.fun1();var page2 = page1.document.getElementById("page2").contentWindow;page2.fun2();

© 手抄报圈