How can I pass values ​​from querystring to javascript?

Now that I have learned how to pass values ​​to a SWF object via flashvars , could you please advise me how I can pass values ​​from a query string to javascript?

What I mean? In the following example, I hard code the xml file to load into the SWF object.

<script type="text/javascript">
    var so = new SWFObject("preview.swf", "", "100%", "100%", "9", "#ffffff");
    so.addParam("allowFullScreen", "true");
    so.addParam("scale", "noscale");
    so.addParam("menu", "false");
    so.addVariable("xmlPath", "xml/exampleData.xml");
    so.write("flashcontent");
</script>

Since the Xml file is created dynamically, xml must be loaded from the value of the query string. (I think).

Suppose my url is http://www.example.com/load.aspx?XmlFile=SomeData

How can I pass it to the javascript side? How..

  so.addVariable("xmlPath", "xml/<% SomeData %>.xml");

or whatever he needs to get it to work.

The UPDATE: . Besides the above example, is there a way to create JavaScript on the server side?

+3
3

- :

function GetQueryString(param) 
{
 var url = window.location.search.substring(1);
    var params = url.split("&");
    for (i=0;i<params.length;i++) 
    {
        var p = params[i].split("=");
        if (p[0] == param) 
        {
            return p[1];
        }
    }   
}

:

so.addVariable("xmlPath", "xml/" + GetQueryString("XmlFile") + ".xml");
+3

window.location.href , :

// Read a page GET URL variables and return them as an associative array.
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }

    return vars;
}
0

function getUrlVars () {var vars = [], hash; var hashes = window.location.href.slice (window.location.href.indexOf ('?') + 1) .split ('&');

for(var i = 0; i < hashes.length; i++)
{
    hash = hashes[i].split('=');
    vars.push(hash[0]);
    vars[hash[0]] = hash[1];
}

return vars;

}

0
source

Source: https://habr.com/ru/post/1772992/


All Articles