- 原理
即构造一个表单来替代原本的get请求使用拼接参数的方式来传递参数 - 构造表单
-
/*comment:查看信息详情 *param: @rowIndex 行索引号 */ function showDetailInfo(fileId){ var url = "<%=request.getContextPath() %>/fileManage/generic/web/redirectViewer.jsp"; //首先创建一个form表单 var tempForm = document.createElement("form"); tempForm.id="tempForm1"; //制定发送请求的方式为post tempForm.method="post"; //此为window.open的url,通过表单的action来实现 tempForm.action=url; //利用表单的target属性来绑定window.open的一些参数(如设置窗体属性的参数等) tempForm.target="_blank"; //创建input标签,用来设置参数 var hideInput = document.createElement("input"); hideInput.type="hidden"; hideInput.name= "fileIds"; hideInput.value= fileId; //将input表单放到form表单里 tempForm.appendChild(hideInput); //将此form表单添加到页面主体body中 document.body.appendChild(tempForm); //手动触发,提交表单 tempForm.submit(); //从body中移除form表单 document.body.removeChild(tempForm); }
新建一个jsp页面来接受参数
-
<%@page pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <%@page import="com.primeton.cap.AppUserManager"%> <meta http-equiv="x-ua-compatible" content="IE=8;" /> <html> <head> <%@include file="/coframe/tools/skins/common.jsp" %> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PDF预览</title> <style type="text/css"> .dtHighLight{ background:#F0F8FF !important; } </style> </head> <body > <div style="width:100%;height:100%"> <iframe id="mainframe" frameborder="0" name="main" style="width:100%;height:100%;" border="0"></iframe> </div> </body> <script type="text/javascript"> </script> </html> <script type="text/javascript"> nui.parse(); $(function(){ var mainIframe=document.getElementById('mainframe'); if(mainIframe){ mainIframe.src="<%=request.getContextPath() %>/fileManage/generic/web/viewer.html?file="+encodeURIComponent("<%=request.getContextPath() %>/com.htfinance.htcm.fileManage.previewFile.previewFileInfo.flow?fileIds=<%=request.getParameter("fileIds") %>"); } }); </script>
使用这种方式的原因就是pdf.js是根据文件流来显示pdf的,我需要传递一个文件的id过去。为了在地址栏隐藏这个id,使用了以上方式。
地址栏不显示参数,主要是在使用pdf.js预览时不在地址栏显示传递的参数
最新推荐文章于 2023-08-14 15:34:47 发布