网页的跳转页面及参数传递方法

文章目录
  1. 1. 跳转页面
  2. 2. 参数传递:

两者都是用git实现代码托管的版本仓库,两者很相似,那它们的区别是?

跳转页面

  1. 直接在跳转的内容外部加上

  2. html加参数onclick=”function()”
    function里写
    window.open("url", _self/__blank(default);
    或者

    1
    2
    window.location.href="url";
    window.history.back(-1);

参数传递:

  1. url传参:
    第一个页面(a.html):

    1
    2
    3
    4
    var obj = a.value; //传给弹出页面参数
    var url = 'jxb.html?obj='+obj;
    url = encodeURI(url);
    window.open(url, "", "width=600,height=400");

    第二个页面(b.html):

    1
    2
    3
    4
    var url = decodeURI(window.location.href);

    var argsIndex = url .split("?obj=");
    var arg = argsIndex[1];

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

  2. cookie传参(不能跨域):

    1
    2
    3
    4
    5
    6
    7
    function setCookie(cname,cvalue){
    document.cookie = cname + "=" + cvalue;
    }
    function getCookie(cname){
    var name = cname + "=";
    var ca = document.cookie;
    }`
  3. localStorage对象传参:

    1
    2
    3
    4
    5
    6
    7
    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()
    父页面:

    1
    2
    <input type="text" name="textfield" id="textfield"/>
    window.open("子页面.html");

    子页面:

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

    如果跨域,子页面还要加上document.domain=”父页面url”

本文总阅读量

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×