首頁  >  文章  >  web前端  >  HTML頁面跳轉及參數傳遞問題

HTML頁面跳轉及參數傳遞問題

小云云
小云云原創
2017-12-06 13:35:502902瀏覽

這篇文章給大家詳細介紹了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 p = doucment.getElementById('要获取字符串的p ID名');
localStorage.string = p.textContent;

b.html:

var p = doucment.getElementById('要写入的p ID名');
p.textContent = localStorage.string;

4. window.opener()

父親頁面:

##

<input type="text" name="textfield" id="textfield"/>

#

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

子頁面:

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

總結

以上內容就是HTML頁面跳轉及參數傳遞問題,希望能幫助大家。

相關推薦:

Javascript頁面跳轉間的常用方法有哪些

Web頁面跳轉並取值的方法指導

關於html頁面跳轉的7篇文章推薦

以上是HTML頁面跳轉及參數傳遞問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn