Monday, 19 August 2013

base_url doesn't work in external js and css file

base_url doesn't work in external js and css file

I was trying to call "base_url()" inside of an external .js file. my
'test.js' file path is "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 I linked that file(my js file is working fine when trying simple
javascript codes) :
<script src="<?php echo base_url(); ?>js/test.js"
type="text/javascript"></script>
but that always said that the access was denied and asked for server
permission. I tried 'site_url()' too, even I tried just an echo"hello" in
'download' function but those didn't work. but when I add that 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 that worked. and in case of external css when I write
background:url('<?php base_url(); ?>images/side.png');
that doesn't work. but if I write
background:url('../images/side.png');
then that works.
so how can I call "base_url()" inside of external .js file and .css file ?
-thanks.

No comments:

Post a Comment