Start html5 app with parameter


I wanted to make a html5 app that would present laser tag game score to customers.
Each game has its GameID as inique identifier.

Idea is that costumer scans QR with url (any QR scaner app) and is sent to Solar 2D built app that would show data for this particular game.

Is there a way to get GameID to html5 app build with Solar? My initial idea is that it would be part of url, as in php “GET” method.

Im happy for any suggestions or ideas on this topic.

You can accomplish this by creating a JS plugin and running it when your app starts.

1 Like

Maybe this could help - New Plugin: Run JavaScript without Leaving Lua


That plugin isn’t really necessary and you’ll most likely get better performance by writing a simple JS plugin yourself.

There are clear samples at or you could copy the basics from Solar2D Playground’s source code:

You really don’t need anything else than a simple JS plugin that runs a function like this: and returns the values back.

Thank you both for tips and links very much!
I used that last link posted by @XeduR to get parameters from url.

Here is how I did it in case someone would use it:



local jsp = require ( "jsurlparameter" )

local params = jsp.get()
local GameID = params.gameid

display.newText (
  text = GameID or "N/A",
  x = display.contentCenterX,
  y = display.contentCenterY,
  font = native.systemFont,
  fontSize = 18

in jsurlparameter.lua (wrapper for simulator).

if system.getInfo("platform") == 'html5' then
   return require "jsurlparameter_js"
   local lib = {}
   setmetatable( lib, {__index = function( t, k )
       return function() 
         print( "WARNING: Placeholder is called for " .. k )
    end} )
lib.get = function ()
		return ( { gameid = "7777-d" } ) --for testing in simulator
  return lib

finally in jsurlparameter_js.js

jsurlparameter_js = {
	get : function () {
    	return getParams(window.location.href);

 * Get the URL parameters
 * source:
 * @param  {String} url The URL
 * @return {Object}     The URL parameters

var getParams = function (url) {
	var params = {};
    var parser = document.createElement('a');
    parser.href = url;
	var query =;
	var vars = query.split('&');
	for (var i = 0; i < vars.length; i++) {
    	var pair = vars[i].split('=');
		params[pair[0]] = decodeURIComponent(pair[1]);
    return params;

That info you put right here in one place was SO helpful for what I’m working on right now. Thank you!