jsp使用get請求跳轉另一個頁面,js自動獲取地址上的參數


續 上個問題攜帶資源id和精度問題

請求頁面時js自動獲取地址欄上的參數

需求就是使用騰訊雲點播,然后需要預覽視頻跳轉到另一個頁面去查看,騰訊那邊的接口是需要獲取到資源id才能夠去點播視頻.我是使用get請求去跳轉到另一個頁面就需要直接從地址欄自動獲取該參數就可以了

例如 http://localhost:8080/xxx?id=37019259256594858934
就會取出 37019259256594858934

  function GetRequest() {
        var url = location.search; //獲取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }

    //調用
    var Request = new Object();
    Request = GetRequest();
    var fileID;
    fileID = Request['resPid'];

    console.log("fileID:"+fileID)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM