0

I have client specific images in many .html pages and I want to redirect the images path to other folder from default folder.

I am trying to achieve the same by following code from external javascript file which is working as expected. But getting an error and HTML source still showing as old file path

I am getting an error as below though Images are loading

GET file:///E:/User/Images/test.png net::ERR_FILE_NOT_FOUND

PS: I am doing this scr

$(document).ready(function () {
  $(function () {
    var img = $("img");
    img.each(function () {
      var src = $(this).attr('src');
      if (src.indexOf('Images/') > -1) { // Default path of the images
        $(this).attr('src', src.replace("Images", "Images/client")); // New path
      }
    });
  });
});

And also, if I check source code, still it is showing as Images/test.png instead of Images/client/test.png

1
  • @RIYAJKHAN, why you redirected him to that page, have you read his code? Commented Mar 11, 2016 at 7:34

2 Answers 2

1

It should be ,

$(this).attr('src', src.replace("Images", "Images/client"));
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry @all... it was typo with client text... I have corrected in question and in my code, still not working...
1

First, you have to use a web server instead of what you are doing,

GET file:///E:/User/Images/test.png net::ERR_FILE_NOT_FOUND

means you are open the file locally.

However, your code is correct and doesn't have any error, you are trying to replace the word (client) with (Images/client) and because your src doesn't contain any word (client), the replace is not taking a place, your correct code should be something like:

$(this).attr('src', src.replace("Images", "Images/client"));

This will work for sure, test and let us know if it worked.

Thanks.

8 Comments

tried from web server as well, still no luck... and also typo corrected in my question and code
are you sure you don't have any error that prevents jquery from loading? cause I tried it just now on my server and it works fine
also, please post the error code here, and make sure you have this path exisit: Images/client with all images inside
I have cross verified in code and html page, test.png is loading from the Images/client... but still getting the error
Sure, hope everything will work fine with you, also, don't forget to close this with accepted answer, for the help of the other who will visit this page after you.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.