Getting FlashVars from the URL – javascript function

Here's a very handy javascript function to grab FlashVars from the URL. 'GUP' Get URL Parameters can sit in your html or in an external js file.

function gup(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];
}

And then when you create your SWF object, pass in the value name you are looking for (in this case 'page')

var so = new SWFObject("loader.swf?page="+gup('page'), ...

4 Comments

  1. […] hab nach stunden googlen & testen das gefunden = Getting FlashVars from the URL – javascript function | ActionScript Scraps bringe die URL_vars so immer noch nicht ins script? wo muss ich alert(gup(‘ID’)); in meinem AJAX […]

  2. Rinus says:

    Hi – thanks for this solution – I’m no code-guy so i have no idea how to pass two variables in this way. Could you help?

    Thanks again

  3. Daniel says:

    Hi Rinus,
    If you see my more recent post http://blog.sitedaniel.com/2008/12/flashvars-as3-getting-values-from-the-url-string/ there is an example there with more information

    Cheers

  4. CjRocks says:

    Thank you! I have searching for it for 3 days and finally i found it. Thank you so much!!!

Leave a Reply