Search code examples
javascriptquery-stringgalleria

javascript add querystring within script


I am using the galleria script for my website, with the facebook mod. I want to modify it a bit, so the albumid that should be showing, is the ID given in query string.

My code is:

Galleria.run('#galleria', { facebook: 'album:000000000', width: 745, height: 550, lightbox: true});

Where i want album:000000000, to be album:-querystring albumid-

For example, my page is album.php?albumid=123456, i want the code to be:

Galleria.run('#galleria', { facebook: 'album:123456', width: 745, height: 550, lightbox: true});

Could someone help me with a certain code?


Solution

  • I can't claim too much familiarity with Galleria, but I have used the JS function below to grab query string variable values.

    function parseURLParams(name, locat) {
            var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(locat);
            if (results) {
                return results[1] || "";
            } else {
                return "";
            }
    }
    

    So if you include the above function in your project, you could potentially set up your code like so:

    Galleria.run('#galleria', { facebook: 'album:' + parseURLParams("albumid", window.location.href), width: 745, height: 550, lightbox: true});
    

    Hope it helps!