php - base_url doesn't work in external js and css file -
i trying call "base_url()
" inside of external .js
file. 'test.js
' file path "js/test.js
".
my test.js
code was:
function download(s){ var w=window.open('<?php base_url(); ?>home/download?f='+s+'.ogg','download','height=100,width=100'); }
and linked file(my js file working fine when trying simple javascript codes) :
<script src="<?php echo base_url(); ?>js/test.js" type="text/javascript"></script>
but said access denied , asked server permission.
i tried 'site_url()
' too, tried echo "hello
" in 'download
' function didn't work. when add code inside of header.php
view file like:
<script type="text/javascript"> function download(s){ var w=window.open('<?php base_url(); ?>home/download?f='+s+'.ogg','download','height=100,width=100'); } </script>
then worked.
and in case of external css when write:
background:url('<?php base_url(); ?>images/side.png');
that doesn't work. if write:
background:url('../images/side.png');
then works.
so how can call "base_url()
" inside of external .js
file , .css
file ?
you can't call base_url() in javascript / css file.
you need put relative path in these js/css files. php scripts aren't aren't run unless they're in .php file.
Comments
Post a Comment