0

I'm creating a little website and I have a variable made in javascript which is assigned through a script.

var alias = "";

After the alias is assigned a value, it is displayed in the URL/Location like so:

file:///C:/TEST/TEST/Desktop/Website/main.html?alias=Jordan

Is there a way to read the variable from another page, so when the page redirects it can say:

Hello 'Jordan'!

I think I heard somewhere that this was possible, but I never knew how!

Also: Is there a way to carry this variable accross MULTIPLE pages without using localstorage/cookies etc.

  • possible duplicate of [How can I get query string values?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values) – Fabrício Matté Nov 12 '13 at 01:38

3 Answers3

1

You'd have to use PHP to access those variables

You could use a simple $_GET['alias'] then to get the string "Jordan"

user2415992
  • 481
  • 7
  • 22
0

You can actually use GET to accomplish this.

http://api.jquery.com/jQuery.get/

or depending on the language you are using, each dynamic language has a GET method.

Hozikimaru
  • 1,144
  • 1
  • 9
  • 20
0

you can use $_GET['alias'] simply


with JavaScript
function getQueryVariable(variable){
       var query = window.location.search.substring(1);
       var vars = query.split("&");
       for (var i=0;i<vars.length;i++) {
               var pair = vars[i].split("=");
               if(pair[0] == variable){return pair[1];}
       }
       return(false);
}

getQueryVariable('alias'); // usage

Source http://css-tricks.com/snippets/javascript/get-url-variables/

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107