Selacius Posted July 21, 2010 Share Posted July 21, 2010 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 More sharing options...
Ingolme Posted July 21, 2010 Share Posted July 21, 2010 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 More sharing options...
ApocalypeX Posted July 21, 2010 Share Posted July 21, 2010 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 More sharing options...
thescientist Posted July 22, 2010 Share Posted July 22, 2010 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 More sharing options...
jeffman Posted July 22, 2010 Share Posted July 22, 2010 Something wrong with cookies here? The array can be serialized (in JSON format, for example) and saved as a cookie string. Link to comment Share on other sites More sharing options...
Ingolme Posted July 22, 2010 Share Posted July 22, 2010 Oh, that's right. I wasn't sure whether Javascript cookies would work on more than one page. Link to comment Share on other sites More sharing options...
dsonesuk Posted July 22, 2010 Share Posted July 22, 2010 the cookie has a size limit of 4 to 5kb, so long as the data does not exceed this, cookie might be an option to consider. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.