鼎之道、易于行
HTML頁面跳轉及參數傳遞問題
時間:2018-05-23
來源:鼎易科技
瀏覽:2970
這篇文章給大家詳細介紹了網站建設中HTML頁面跳轉及參數傳遞問題,需要的朋友參考下吧

HTML頁面跳轉:
1 | window.open(url, "", "width=600,height=400"); |
第二個參數:_self,在當前窗口打開窗口;_blank(默認值),在另外的新建窗口打開新窗口;
1 2 3 | window.location.href="http://www.jb51.net"; //在同當前窗口中打開窗口window.history.back(-1); //返回上一頁面 |
HTML參數傳遞:
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 | 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對象傳參:
a.html:
1 2 | var div = doucment.getElementById('要獲取字符串的DIV ID名');localStorage.string = div.textContent; |
b.html:
1 2 | var div = doucment.getElementById('要寫入的DIV ID名');div.textContent = localStorage.string; |
4. window.opener()
父頁面:
1 | <input type="text" name="textfield" id="textfield"/> |
1 | window.open("子頁面.html"); |
子頁面:
1 | window.opener.document.getElementByIdx('textfield').value='123123123'; |
總結
以上所述是小編給大家介紹的HTML頁面跳轉及傳遞參數問題,希望對大家有所幫助。








信息保護中請放心填寫
