Can I add values into a Javascript file like the example below? /javascript.js?a=whatever&b=whatever Then get them with '+a+' and '+b+' Is it ok to do that? Thanks for your help!
no. you cant. but you can add variables to a php script. rename your js to .php, then have: /javascript.php?a=whatever&b=whatever and within the file, just iterate $_GET or do absolute varnames like var a = '<?=$_GET['a']?>', b = '<?=$_GET['b']?>; hth
Actually, you can. 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]; } Code (markup): The function above will return the value of an URL parameter. Usage example: gup('hello'); // This returns 'world' from http://domain/page.php?hello=world Code (markup): taken from: http://www.netlobo.com/url_query_string_javascript.html
this is not correct- it will get parameters to the page that EMBEDS the js, not params to the js itself. different problem altogether.
Awful code, I hate it when people use regular expressions instead of parsing a string which is usually much easier. Also you have to call decodeURIComponent on the string.