如何擷取url中的參數並傳遞給iframe中的報表

來源:互聯網
上載者:User

標籤:分類樹   url   ifrme   finereport   

在使用報表軟體時,使用者系統左邊一般有分類樹,點擊報表節點就會在右側網頁的iframe中顯示出報表,同時點擊的時候也會傳遞一些參數給網頁,比如時間和使用者資訊等。如何使網頁中的報表能夠擷取到傳遞過來的參數呢?以下用報表軟體FineReport簡單介紹一些。

具體實現過程

將報表產生頁面時,給網頁添加onload事件,首先擷取url中的參數,然後嫁接到iframe的src上,或者通過獲得的參數拼接處完整的報表url賦給iframe的src。

<html><head><title>FineReport Demo</title><meta http-equiv="Content-Type" content="text/html; charset=GBK"><script type="text/javascript" src="/WebReport/ReportServer?op=emb&resource=finereport.js"></script><script type="text/javascript">function autoLoad(){//返回從問號 (?) 開始的 URL(查詢部分)var paraString = location.search;   //多個參數用&分隔,將參數字串轉為數組,使每個參數值存於一個數組元素中var paras = paraString.split("&");  //每個數組元素中"="後面的值即參數值var reportName = paras[0].substr(paras[0].indexOf("=") + 1); var area = paras[1].substr(paras[1].indexOf("=") + 1);var province = paras[2].substr(paras[2].indexOf("=") + 1);var city = paras[3].substr(paras[3].indexOf("=") + 1);//使用擷取的參數值拼接出最終的urlvar reportURL = "/WebReport/ReportServer?reportlet=" + reportName + "&area=" + area + "&province=" + province + "&city=" + city;//url中可能包含中文或特殊字元因此需要進行編碼轉換,注意需要先引入finereport.jsreportURL = FR.cjkEncode(reportURL);//將新的報表路徑賦給報表所在iframe的srcdocument.getElementById("reportFrame").src = reportURL; }//載入網頁時調用autoLoad方法window.onload = autoLoad;</script></head><body><iframe id="reportFrame" width="900" height="400"></iframe></body></html>

將代碼儲存為geturlpara.html,儲存在工程下的page_demo檔案夾下。

使用管理員登入決策平台,點擊管理系統>報表管理,點擊添加連結,連結路徑為:page_demo/geturlpara.html?report=doc/Parameter/MultiValue/MultiValue.cpt&area=華東&province=江蘇&city=無錫,名稱為:url參數傳遞給iframe中的報表,如:

650) this.width=650;" src="http://img.blog.csdn.net/20161124165137377" />

這樣重新整理fs,就可以看到左側分類樹中多了一個節點,點擊該節點後,就可以在右側網頁的iframe中顯示出報表包括傳遞給網頁的參數。

效果查看

如,點擊左側“url參數傳給iframe中的報表”節點時,即開啟相對應的連結,對應網頁就會在中間地區顯示出來:

650) this.width=650;" src="http://img.blog.csdn.net/20161124165158674" />

如何擷取url中的參數並傳遞給iframe中的報表

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.