JavaScrip acquisition parameters passed to jump between pages

As a novice white, there are a lot of knowledge I need to continue to accumulate learning, although this article is very simple, but a good memory as bad written Well, as my own personal notes should, or can, please see this article great God made you a lot of inadequacies!

Ado, here's get to the bar!

How to get JavaScript parameters passed to jump between pages:

Take the jump to another page after a successful login, for example:

Jump to another page, login page of the corresponding js 1. After a successful login the main code (in this case the transfer is to fill in the login user account can also be delivered more of the same method, just add back the parameters you want to pass you can):

//alert("登录成功!");
window.location.href = "picture.html?username=" + account;

2. After you log in successfully acquired the corresponding picture parameter login.js passed js:

// obtain the URL of the login page and extracts the transmission parameter which 
function GET_URL () {
     var tmpArr, the QueryString;
     var testpaperName;
     var URL = document.location.toString (); // Get URL parameters of 
    the console.log (URL );
     IF ! ( "?" URL.lastIndexOf () = -1 ) { 
        the QueryString = url.substring (URL.lastIndexOf ( "?") +. 1 , URL.length); 
        tmpArr = QueryString.split ( "&") ; // separation parameter 
        the console.log (tmpArr);
         for (I = 0; I <= tmpArr.length; I ++ ) {
             the try { 
                the eval (tmpArr [I]); 
            } the catch(e) {
                var re = new RegExp("(.*)=(.*)", "ig");
                re.exec(tmpArr[i]);
                try {
                    eval(RegExp.$1 + "=" + "\"" + RegExp.$2 + "\"");
                } catch(e) {}
            }
        }
    } else {
        QueryString = "";
    }
    if(username) {
        testpaperName = unescape(username);
        console.log(testpaperName);
        $('#h2TestpaperName') .html (testpaperName);
    } 
    Return testpaperName;   // this variable is that we extracted from the url login.js the passed parameters: username (user account) 
}

 

Guess you like

Origin www.cnblogs.com/huiing/p/11367532.html