HTML頁面之間跳轉與傳值

2021-09-24 14:08:46 字數 1609 閱讀 7050

跳轉的方法如下:

方法一:

window.location.href = "b.html";

window.history.back(-1);

方法三:

self.location = "b.html";

方法四:

top.location = "b.html";

有關問題的思考:

第一,為什麼給window.location和window.location.href賦值時一樣的,都可以跳轉?

思考:location是location.href的簡寫,無論是訪問值還是賦值。

從功能上,location等於location.href;

但從本體論上,location是乙個物件,location.href是它的乙個屬性。

這種怪異的行為應該是為了相容無疑。

第二,給location賦值的時候,如果跳轉的頁面不是在同乙個目錄下,需要把完整的url寫上。如:當前location.href為 ,如果要跳轉到 就不能只是www.baidu.com,必須把url寫完整。

傳值的方法如下:

方法一:url傳參(?後面的引數)(去哪兒網筆試題,把url後面的引數解析為物件)

window.location.href = "search?q=hello&oq=hello"

function parseurl(url);

var arr = ;

for(var i=0;iarr = para[i].split("=");

res[arr[0]] = arr[1];

return res;

方法二:cookie傳參

function setcookie(cname,cvalue,exdays){

var d = new date();

d.settime(d.gettime() + (exdays*24*60*60*1000));

var expires = "expires=" + d.toutcstring();

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

function getcookie(cname){

var name = cname + "=";

var ca = document.cookie.split(";");

for(var i=0;ivar c = ca[i];

while(c.charat(0)==' '){

c = c.substring(1); 

if(c.indexof(cname) == 0){

return c.substring(name.length,c.length);

return "";

方法三:h5中web storage中的localstorage物件

localstorage.setitem("lastname","lu");

或者localstorage.lastname = "lu";

localstorage.getitem("lastname");

或者localstorage.lastname;

頁面跳轉傳值接收

遇到乙個問題,有乙個頁面a,頁面b和頁面c都能跳轉到頁面a,然後頁面b需要傳值到頁面a,執行函式取到後台資料,而從頁面c進入就不需要,然後問題就來了 c1 window.location.href.split 1 c2 c1.split 1 頁面a的js這樣寫確實能取到從頁面b傳來的資料,但是從頁面...

html頁面跳轉方式 跳轉傳參

一,頁面跳轉方式 在原有的頁面 1.利用a標籤 素材2.jq跳轉 function add richtext item 二 頁面跳轉傳參 開啟新的頁面 a頁面寫法 url boke bokedetail list.html?bokeinfo id 此處拼接內容 window.open url b頁面...

html頁面傳值

html頁面傳值 一是資料掛載 區域性載入方式 二是a標籤方式 三是window.location.href方式 1.資料掛載,區域性載入方式 在父標籤中繫結要傳遞的引數 container fluid data id ids 0 通過後台跳轉頁面 var url user edit.do 或直接指...