Javascript Helper File Messing Up CSS Formatting??? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Javascript Helper File Messing Up CSS Formatting??? (/showthread.php?tid=53147) |
Javascript Helper File Messing Up CSS Formatting??? - El Forum - 07-12-2012 [eluser]dhall[/eluser] I have put my javascript functions in helper files and then load them in the Controllers where needed. When I do this though it messes up the formatting on my pages. If I place the javascript directly inside the <head> tags though does not cause this problem. I checked the html output in both cases and it looks fine from what I can see. Any idea why that is? What is the best way to store your javascript functions? Javascript Helper File Messing Up CSS Formatting??? - El Forum - 07-12-2012 [eluser]CroNiX[/eluser] Javascript is supposed to be loaded/used in the <head>. I store my javascript in javascript files, and then load them in the head of the document. Code: <skript src="http://mysite.com/assets/js/some_file.js" type="text/javascript" charset="utf-8"></skript> With skript spelled correctly (forum removes them) Javascript Helper File Messing Up CSS Formatting??? - El Forum - 07-12-2012 [eluser]dhall[/eluser] Thanks CroNiX, That got it working but now my functions are there to view on every page, even though they are only needed if the user goes to a certain page. How can I prevent it from doing that? I also have several more functions that I want to create to run when another certain page loads. If I do as you suggest, wouldn't it try to run those functions every time every page loads, or is there a way to have it only load on the specific page I want? Thanks for the help! Javascript Helper File Messing Up CSS Formatting??? - El Forum - 07-12-2012 [eluser]CroNiX[/eluser] I use a template library, which allows me to select which css/js/etc get loaded, and I set that in the controller only loading what that controller needs. Javascript Helper File Messing Up CSS Formatting??? - El Forum - 07-13-2012 [eluser]dhall[/eluser] I use a template system also but more simple than your probably. I just have header, menu, main_content, footer. To do like you are talking, would I break the header into 2 sections? Could you give me an example of how that would work? Javascript Helper File Messing Up CSS Formatting??? - El Forum - 07-13-2012 [eluser]CroNiX[/eluser] You can pass variables to your header like any other view. Those variables can be css files, js files or whatever else. controller Code: $assets['css'] = array( Then in the <HEAD> of your header view, Code: if (count($css)) |