Javascript + base_url() |
[eluser]ELRafael[/eluser]
Greetings.... Here's my doubt. i have a javascript file (global.js) that loads into view. (script src="....") so far so good. but inside that js file, i have a Ajax.Updater calling. Code: new Ajax.Updater('/subdir/controller/method/args', 'my_div', {}); What I want is put a base_url in '/subdir/', cause probably the subdir of application will change (i don't know what will be the name, so i need to use base_url). If the js was wrote in the view, it's ok, i could use Code: new Ajax.Updater('<?=base_url();?>controller/method..... But that's not the case :blank: Helps? Ideas? Lights? Thanks
[eluser]gtech[/eluser]
Oh hang on I got it!! view.php Code: <script> Then base will be a variable available in the javascript. [edit] I dug out some old code so I know it works.. myjavascript.js Code: ..
[eluser]Derek Allard[/eluser]
You are welcome to see how I did it in BambooInvoice and also in http://video.derekallard.com if that's helpful.
[eluser]ELRafael[/eluser]
can i do this in css too? Code: background-image: url(something like that joe/image.png); i'll see that js after lunch :-P ah! thanks
[eluser]Derek Allard[/eluser]
You can't use base_url in CSS, because the PHP won't get parsed, but you can just say Code: background-image: url(/something_like_that_joe/image.png); Notice the "/" at the beginning? It means "start from the web root". There lots of info on the forum if you poke around for it.
[eluser]ELRafael[/eluser]
OK Derek, that i knowed. My fck problem is that the application maybe move someday to a subdir. If this happen, i'm fc$%*, cause it's a very big application. And i don't wanna change all views/css/javascript. That solution about base in javascript works fine (thanks gtech). Today my app is working very well. The css has "/" in the background-image element. In fact, i only ask to see if someone has a better solution than mine. It's not a problem today. Thanks
[eluser]joeles[/eluser]
As far as the CSS goes, I keep stylesheets and their related images in the same directory so I can reference the images relatively as "background: url(image.gif) ...". Then I use base_url in my html to include the stylesheet as usual. I move sites to different locations/directories all the time with no problem. |
Welcome Guest, Not a member yet? Register Sign In |