window.open()参数传递及获取

时间:2024-05-20 15:38:35

 

window.open()参数传递及获取

1, 最基本的弹出窗口代码
   window.open('page.html');

2, 经过设置后的弹出窗口
   window.open('page.html', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')   //该句写成一行代码
   参数解释:
      window.open 弹出新窗口的命令; 
  'page.html' 弹出窗口的文件名; 
  'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替; 
  height=100 窗口高度; 
  width=400 窗口宽度; 
  top=0 窗口距离屏幕上方的象素值; 
  left=0 窗口距离屏幕左侧的象素值; 
  toolbar=no 是否显示工具栏,yes为显示; 
  menubar,scrollbars 表示菜单栏和滚动栏。 
  resizable=no 是否允许改变窗口大小,yes为允许; 
  location=no 是否显示地址栏,yes为允许; 
  status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;

下面是怎么传入参数:

1、带参数打开新窗口

$window.open("/bdfence/bdfence-division/bdfence.html?vehicleId="+ id  );


2、获取参数

var afterUrl =  window.location.search.substring(1);(问号以后的字符串)

var afterEqual = afterUrl.substring(afterUrl.indexof('=')+1).toUpperCase();(等号以后的字符串,及你所要的参数)

下面是事例代码:

	<td bgcolor="#FFFFFF" align="center">
						<input type="button" value="删除" onclick="shenqingDel(<s:property value="#shenqing.id"/>)"/><!--
						<form action="<%=path %>/shenqingHuifu.action?id=${id}" method="post">
						<input   name="zt" type="text" value="请输入回复信息" /> 
						<input type="submit" value="提交"/>
						</form>
						
					-->
					
					<input type="button" value="回复" onclick="shenqingHuifu(<s:property value="#shenqing.id"/>)"/>
					</td>

js代码:

        <script language="javascript">
           function shenqingDel(id)
           {
               if(confirm('您确定删除吗?'))
               {
                   window.location.href="<%=path %>/shenqingDel.action?id="+id;
               }
           }
           
           function shenqingHuifu(id)
           {
           window.open ("<%=path %>/admin/shenqing/huifu.jsp?id="+id,"回复窗口","fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no, copyhistory=no,width=350,height=140,left=200,top=300");
               //var strUrl = "<%=path %>/admin/shenqing/shenqingHuifu.jsp?id="+id;
             //  alert( "用户名:"+document.form1.username.value+",密码:"+document.form1.passwd.value);
               //var strUrl = "<%=path %>/shenqingHuifu.action?id="+id;
              // window.location.href=strUrl;
           }
           
        </script>

这里面是嵌套了一个另一个网页:

huifu.jsp

<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>回复窗口</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<style type="text/css">
.text1{width:150px; height:60px}
</style>
  </head>
  
  <body>  
  <form action="<%=path %>/shenqingHuifu.action" method="post"> 
  <table >
    <tr>
      <td>请输入回复内容<input type="hidden" name="id" value="<%=request.getParameter("id") %>"></td>
      <td>  <input type="text" name="zt" class="text1"></td>
    </tr>
    <tr>
      <th><input type="submit" value="提交"/></th>
    </tr>
  </table>
</from>
  </body>
</html>