0

I'm using small jQuery script to change src argument on img tag. It works without any problems on my hosting but after migrating website on client's hosting this script doesn't work at all.

I have checked with Firebug and the script is there. I also tried to access to [website]/misc/ui/jquery.ui.core.min.js in browser and jQuery is shown. I tried to install jquery_update module and change versions of jQuery (with and without CDN). None of this helped.

I noticed on 'Status report' page warning because of PHP mbstring extension.

enter image description here

Is this could be the possible reason for not working?

In Firebug my script shows like:

<script><![CDATA[ ]]><!--//--><![CDATA[// ><!-- jQuery(document).ready(function() { var img; img = '/sites/all/themes/ave/img/logo2.png'; jQuery('.logo-img a img').attr("src", img); }); //--><!]]><![CDATA[ ]]></script> 

Do you have some ideas or maybe similar experience?

2
  • What happens when you Aggregate JavaScript files? Is it just your script or other scripts as well? Have you looked at the browser console log? Have you tried putting a browser debug point in it to see if it is hit? Does the new site run on https protocol? Commented Sep 11, 2014 at 14:34
  • I tried to aggregate JavaScript files and result is the same. In browser console I got one 'SyntaxError: syntax error' (<![CDATA[) exactly on my script. I updated my question, so you can take a look how the script looks like when I look it through Firebug. Website doesn't run on https protocol. Commented Sep 11, 2014 at 14:52

1 Answer 1

1

Your issue is in this line

img = '/sites/all/themes/ave/img/logo2.png'; 

It should be something like this:

img = location.protocol + "//" + location.host + '/sites/all/themes/ave/img/logo2.png'; 

and if that does not work just inspect the src param of the image and adjust accordingly.

And perhaps replace the whole script with this:

(function ($, Drupal, window, document, undefined) { Drupal.behaviors.MYMODULE = { attach: function(context, settings) { var img = location.protocol + "//" + location.host + '/sites/all/themes/ave/img/logo2.png'; $('.logo-img a img').attr("src", img); } }; })(jQuery, Drupal, this, this.document); 
1
  • Thanks a lot, this is working for me. I also tried to add my script in file and implement it in template.php instead adding it inline, that is working too. Commented Sep 11, 2014 at 16:17

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.