Jump to content

Persistent JS Variables


Selacius

Recommended Posts

I am wondering how it would be possible to have a variable/s which are able to persist throughout multiple web-pages. For example, I setup my quest array which handles all of the quest information when the main exploration page loads up. Now I would like to only have to populate these arrays once and somehow allow them to be accessed from different pages which stem off the exploration page.Any clues? Thanks

Link to comment
Share on other sites

You would have to look into PHP to store the variables in sessions. If you want a purely Javascript solution, you'll have to add a query string to the URL of your links and have the script of the other pages read it.

Link to comment
Share on other sites

GET URL variables.

function getUrlParameter(name){  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  var regexS = "[\\?&]"+name+"=([^]*)";  var regex = new RegExp( regexS );  var results = regex.exec( window.location.href );  if(results == null) {    return "";  } else {    return results[1];  }}

Link to comment
Share on other sites

if you use GET and pass via query string, people could manipulate it and alter the game. I think you're best is via PHP + SESSIONS, or MySQL.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...