历史版本3 :通过JS获取当前页面URL网址信息 返回文档
编辑时间: 内容长度:图片数:目录数: 修改原因:

目录:

1. 描述编辑

在平时的报表开发中,我们通常会遇到要获取当前打开报表页面的URL网址相关信息,虽然目前FR内置了部分系统参数能满足一定的需求,但不够完善。比如要获取URL对应的"标签名称",系统参数中就没有提供。

222

2. 思路编辑

可以通过js脚本来获取URL网址相关信息。

3. 示例编辑

打开 %FR_HOME%\webapps\webroot\WEB-INF\reportlets\GettingStarted.cpt 文件,给“查询”按钮添加点击事件,如下图所示:

222

js代码:

//设置或获取整个 URL 为字符串 var test1 = window.location.href; alert('URL地址: '+test1); //window.location.protocol(设置或获取URL的协议部分) var test2 = window.location.protocol; alert('URL协议: '+test2); //window.location.host(设置或获取URL的主机部分) var test3 = window.location.host; alert('URL主机: '+test3); //window.location.port(设置或获取与URL端口号) var test4 = window.location.port; alert('URL关联端口: '+test4); //window.location.pathname(设置或获取与URL的路径部分(文件地址)) var test5 = window.location.pathname; alert('URL文件路径地址: '+test5); //window.location.search(设置或获取URL属性中跟在问号后面的部分) var test6 = window.location.search; alert('URL问号后部分: '+test6); //window.location.hash(设置或获取URL属性中在“#”后面的内容) var test7 = window.location.hash; //获取URL对应的"标签名称" var test7 = document.title; alert('URL标签名称: '+test7); 

保存后,效果如下:

222