js 利用url傳遞引數

2021-06-07 15:03:44 字數 716 閱讀 9727

原始請求:http://localhost:8093/cctest/cc/mainframes/mainright.html?gg=1

alert(window.location.pathname); // 彈出 /cctest/cc/mainframes/mainright.html

alert(window.location.search); // 彈出 ?gg=1

alert(window.location.href); // 彈出 http://localhost:8093/cctest/cc/mainframes/mainright.html?gg=1

得到引數後,還需要對字串進行分割合併等處理,才能獲得你想要的引數。

location物件 

含有當前url的資訊. 

屬性 href 整個url字串. 

protocol 含有url第一部分的字串,如http: 

host 包含有url中主機名:埠號部分的字串.如 

hostname 包含url中主機名的字串.如 ;

port 包含url中可能存在的埠號字串. 

pathname url中"/"以後的部分.如~list/index.htm 

hash "#"號(cgi引數)之後的字串. 

search "?"號(cgi引數)之後的字串.

js 利用url傳遞引數

原始請求 http localhost 8093 cctest cc mainframes mainright.html?gg 1 alert window.location.pathname 彈出 cctest cc mainframes mainright.html alert window.l...

js獲取url傳遞引數

寫頁面發現需要根據傳遞引數呈現不同的效果,頁面傳遞並獲取引數一直不太熟悉,恰好發現這篇文章,收藏下。今天碰到要在乙個頁面獲取另外乙個頁面url傳過來的引數,一開始很本能的想到了用 split 這樣一步步的分解出需要的引數。後來想了一下,肯定會有更加簡單的方法的!所以在網上找到了兩個很又簡單實用的方法...

url傳遞中文引數

send.html var key 測試 通常,如果我們直接將中文寫在url中,得到的卻是一堆亂碼 e6 b5 8b e8 af 95 因為這涉及到編碼問題。如果你設定了編碼方式為utf 8,則它會將中文編譯為英文,如果對應的頁面的編碼方式也為utf 8,則就直接顯示編譯後的中文 解決方法 1.en...