Welcome Guest, Not a member yet? Register   Sign In
Pass site_url() to included javascript file
#1

[eluser]Andy UK[/eluser]
Hi guys,

for my google maps mashup i ended up with a lot of code in my header and decided to move it to a separate .js file in my scripts folder.

Code:
<?php if(isset($gmap_multiple_markers)) {    
        echo "include google maps here with key between script tags...";
        echo "Include map_search.js javascript file here between script tags...";
        }
    ?>

All well and good, but there's a part of that map_search.js file that needs to read in other files and i need to give it the current site url which changes depending on the language be used.

The question therefore is: How can i pass a variable or a constant to the included javascript file so that the site url is included in the path?

Thanks for your help!

Andy.
#2

[eluser]WanWizard[/eluser]
Create a global javascript variable in the header that contains the base url?
Code:
<script type="text/javascript">
/* <![CDATA[ */
    var global_baseurl = "<?php echo base_url(); ?>";
/* ]]> */
</script>
#3

[eluser]Andy UK[/eluser]
Thanks WanWizard. That worked great!




Theme © iAndrew 2016 - Forum software by © MyBB