HTML页面跳转及参数传递

HTML页面跳转

window.open(url, "", "width=600,height=400");
第二个参数:_self,在当前窗口打开窗口;_blank(默认值),在另外的新建窗口打开新窗口;

window.location.href="https://www.yinxi.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

  1. cookie传参:

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

  1. 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;

  1. window.opener()

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。