HTML页面跳转及参数传递

HTML页面跳转:

window.open(url, "", "width=600,height=400");
 
//第二个参数:_self,在当前窗口打开窗口;_blank(默认值),在另外的新建窗口打开新窗口;
 
window.location.href="http://www.jb51.net";     //在同当前窗口中打开窗口
 
window.history.back(-1);    //返回上一页面
 
 <a href="http://www.baidu.net"  target="_blank">

HTML参数传递:

1. url传参:

第一个页面(a.html):
 
var obj = a.value; //传给弹出页面参数
var url = 'jxb.html?obj='+obj;
url = encodeURI(url);
window.open(url, "", "width=600,height=400");
 
第二个页面(b.html):
 
var url = decodeURI(window.location.href);
 
var argsIndex = url .split("?obj=");
var arg = argsIndex[1];

注:中文传输:可以在页面a用encodeURI 编码url  在b页面用decodeURI解码url

2. cookie传参:

function setCookie(cname,cvalue){
    document.cookie = cname + "=" + cvalue;
}
function getCookie(cname){
    var name = cname + "=";
    var ca = document.cookie;
}

3. localStorage对象传参:

a.html:
var div = doucment.getElementById('要获取字符串的DIV ID名');
localStorage.string = div.textContent;
 
b.html:
var div = doucment.getElementById('要写入的DIV ID名');
div.textContent = localStorage.string;

4. window.opener()

父页面:
 
<input type="text" name="textfield" id="textfield"/>
 
window.open("子页面.html");
 
子页面:
 
window.opener.document.getElementByIdx('textfield').value='123123123';

页面跳转时参数携带与参数接收的几种方式

1.js中页面跳转

location.href = path + "/weixin/jsp/submitNewSuccess.jsp?package_number="+package_number  

参数接收方式:

  1. <script type="text/javascript">  
  2.     var package_number = "<%=request.getParameter("package_number")%>";  
  3. </script>  

2.java代码中页面重定向

request.setAttribute("openid", openid); 

request.getRequestDispatcher("/weixin/jsp/weixinLogin.jsp").forward(request, response);  

页面中参数接收方式:

var openid =  "<%=request.getAttribute("openid")%>";  

把参数在java代码里面放到session里面:

request.getSession().setAttribute("openid", openId());  

页面中接收参数的方式:

  1. <script type="text/javascript">  
  2.     var openid =  "<%=request.getSession().getAttribute("openid")%>";  
  3. </script>  
  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值