xiparos Posted January 16, 2015 Share Posted January 16, 2015 Hi Prestashop members, I don't quite understand why the following method does not work in Prestashop 1.6.0.9. I am trying to add javascript snippet into <head> tags by using hookHeader() in module, for example, public function hookHeader(){ $jscript = '<script type="text/javascript">//<![CDATA[$(window).load(function(){$.uniform.restore("input");});//]]></script>'; return $jscript; } By executing the module, I noticed that the returned javascript snippet has been included within <head> tags in webpage, like <head> ...... <script type="text/javascript"> //<![CDATA[$(window).load(function(){$.uniform.restore("input");});//]]> </script> </head> But this snippet doesn't work at all, however, after using the more traditional way to add js file, public function hookHeader() { // the js content has been put into main.js $this->context->controller->addJS(($this->_path).'js/main.js'); ....... } in html file, <head> <script type="text/javascript" src="/prestashop/module/test/js/main.js"></script> </head> It works as expected. Could you please tell me how should I do if I want to use the first way to include js snippet within <head> tag ? Thanks in advance. Link to comment Share on other sites More sharing options...
vekia Posted January 16, 2015 Share Posted January 16, 2015 and what browser console spawns if you use first method? can you check it? Link to comment Share on other sites More sharing options...
xiparos Posted January 16, 2015 Author Share Posted January 16, 2015 and what browser console spawns if you use first method? can you check it? Hi, Vekia, Thanks for your reply. I got no warning and error from console, since there is just one module installed in PS for test purpose. here is a screenshot of js snippet. Link to comment Share on other sites More sharing options...
bellini13 Posted January 17, 2015 Share Posted January 17, 2015 I don't believe he asked for a javascript snippet, he was asking about the Browsers console window, and if it had any errors listed. what happens if you try to execute that javascript directly from the browser console? also why are you trying to load the javascript inline, and not from a .js file? lastly, you are executing your javascript on "window load". perhaps that is too early and you should try document ready? $(document).ready(function() { //your javascript command here }); Link to comment Share on other sites More sharing options...
xiparos Posted January 21, 2015 Author Share Posted January 21, 2015 I don't believe he asked for a javascript snippet, he was asking about the Browsers console window, and if it had any errors listed. what happens if you try to execute that javascript directly from the browser console? also why are you trying to load the javascript inline, and not from a .js file? lastly, you are executing your javascript on "window load". perhaps that is too early and you should try document ready? $(document).ready(function() { //your javascript command here }); Hi bellini13, Thanks for your reply. answer 1: I now understand what Vekia means "browser console spawns". answer 2: I just want to know there is difference or not between these two methods to load javascript snippet. answer 3: I've tested with $(document).ready(), it doesn't work, it's a specific block of code which prevents uniform.js styling the elements in html, whatever, it's not so important. I'll try to execute js directly from debug console and give my feedback. Cheers Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now