Getting HTML5 GET params

If you want to be able to get GET params for whatever reason (such as allowing others to embed your games while changing select config values easily)

myawesomegame.com/embed/?lang=en&show_splash=1

Then you can use something like this

if html5 then
local lang = html5.run("try{(document.URL.match(/lang=([a-z,A-Z])\\w+/)[0]).split('=')[1];}catch(err){}")
local show_splash = html5.run("try{(document.URL.match(/show_splash=([0-9])\\w+/)[0]).split('=')[1];}catch(err){}")
...
end

Maybe a web expert could get a better solution, but this is the simplest, shortest way I could find that seems to work fine.

It can return “NULL” and “undefined” if the params you are looking for are not set properly so you will need to handle that and use default values in those cases.

I guess that’s fine. I probably wouldn’t have thought of doing the processing in Javascript and instead got the whole window location (url) and parsed it in Lua using string.gmatch().

1 Like

A small helper module which does that would probably be worth doing. Have to make sure the input is sanitized whichever method is used.

1 Like