I have two HTML pages. I am trying to send parameters to the second URL from the first URL using window.location.href
The code I have tried is:
me1.html
<html>
<head>
</head>
<body onload="redirectPage();">
<script>
function redirectPage(){
var a = "me";
var b = "here";
var url = "me2.html?a="+String(a)+"&b="+String(b);
window.location.href = url;
}
</script>
</body>
</html>
me2.html
<html>
<head></head>
<body onload="getValues();">
<script>
function getValues(){
var a,b;
var SearchString = window.location.search.substring(1);
var VariableArray = SearchString.split('&');
for(var i = 0; i < VariableArray.length; i++){
var KeyValuePair = VariableArray[i].split('=');
if(KeyValuePair[0] == "a"){
a = KeyValuePair[1];
console.log("CUSTOMER KEY: "+a);
alert("A: "+String(a));
}
else if(KeyValuePair[0] == "b"){
b = KeyValuePair[1];
console.log("USER KEY: "+String(b));
alert("B: "+b);
}
}
</script>
</body>
</html>
I don't get any alerts, though the URL formed is correct. what may be the issue with the code?