Welcome Guest, Not a member yet? Register   Sign In
CI constant in JS script
#2

[eluser]xenon-dev[/eluser]
As long as the JS file is external, you can't do any server-side thingies in it. However, you could create some macros, and parse the JS file into a php variable, then replacing the macros. It would look like this (roughly):

the JS file:
Code:
<#BASE_DIR#>

and in PHP you would have:
Code:
$js = file_get_contents( 'file.js' );

$js = str_replace( '<#BASE_URL#>', 'your base url', $js );

After making the replacements, you will have to either output the JS as part of the current page (in a script block) and removing the script src from your page (so the functions, vars, etc, will not be defined again), or overwrite the existing JS file, while keeping the script src tag.

I can't see a more elegant solution, so I hope this will help you. Cheers!


Messages In This Thread
CI constant in JS script - by El Forum - 08-28-2007, 05:00 AM
CI constant in JS script - by El Forum - 08-28-2007, 06:38 AM
CI constant in JS script - by El Forum - 08-28-2007, 06:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB