1

I have datatable rows links coming with data and I wanna change part of the link text.

So, for example, when it's 200.0.0.10 change it to 160.11.10.12

I tried it with this code but nothing happened, the link remains unchanged:

var url = (data['Chemin'])

window.location.href = url.replace("http:\\200.0.0.10", "\\160.11.10.12\Images");
3
  • 1
    Are you sure than data['Chemin'] value is http:\\200.0.0.10? Commented Mar 12, 2018 at 15:39
  • If you are just wanting to replace them... why are you trying to redirect your whole page to it in the same go? Commented Mar 12, 2018 at 15:40
  • yes in my data['Chemin'] value is http:\\200.0.0.108............and i wanna just change http:\\200.0.0.10 Commented Mar 12, 2018 at 15:51

1 Answer 1

1

Use // in your url and it should work.

 window.location.href = url.replace("http:\\200.0.0.10", "http://160.11.10.12/Images");

If that doesn't work it's because of the escaped backslashes so do:

 window.location.href = url.replace("http:\\\\200.0.0.10", "http://160.11.10.12/Images");

Using backslashes \ in JS is an escape character which means that the next character has special meaning e.g. \n means new-line. So if you want a \ in a string you have to double it.

Sign up to request clarification or add additional context in comments.

Comments

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.