美文网首页
2018-07-30 HTML页面跳转及参数传递

2018-07-30 HTML页面跳转及参数传递

作者: waterte | 来源:发表于2018-07-30 16:54 被阅读0次

    HTML页面跳转及参数传递

    HTML页面跳转:

    window.open(url,"","width=600,height=400");

    //第二个参数:_self,在当前窗口打开窗口;_blank(默认值),在另外的新建窗口打开新窗口;

    window.location.href="http://www.jb51.net";//在同当前窗口中打开窗口

    window.history.back(-1);//返回上一页面

    HTML参数传递:

    1. url传参:

    第一个页面(a.html):

    varobj = a.value;//传给弹出页面参数

    varurl ='jxb.html?obj='+obj;

    url =encodeURI(url);

    window.open(url,"","width=600,height=400");

    第二个页面(b.html):

    varurl =decodeURI(window.location.href);

    varargsIndex = url .split("?obj=");

    vararg = argsIndex[1];

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

    2. cookie传参:

    functionsetCookie(cname,cvalue){

    document.cookie = cname +"="+ cvalue;

    }

    functiongetCookie(cname){

    varname = cname +"=";

    varca =document.cookie;

    }

    3. localStorage对象传参:

    a.html:

    vardiv = doucment.getElementById('要获取字符串的DIV ID名');

    localStorage.string = div.textContent;

    b.html:

    vardiv = doucment.getElementById('要写入的DIV ID名');

    div.textContent = localStorage.string;

    4. window.opener()

    父页面:

    window.open("子页面.html");

    子页面:

    window.opener.document.getElementByIdx('textfield').value='123123123';

    相关文章

      网友评论

          本文标题:2018-07-30 HTML页面跳转及参数传递

          本文链接:https://www.haomeiwen.com/subject/udwfvftx.html