How do I replace all occurences of "http://localhost" in a string in javascript?
I have res=res.replace(/^http\:\/\/localhost, url);
, but it does not work. How do I fix it?
url
is a variable and but "localhost" is a string.
UPDATE:
With the solutions below, I still get: ReferenceError: localhost is not defined
. What am I missing?
UPDATE 2:
This is the (Perl) code that inserts the JS on the page:
$form .= qq|<script>res='$doc'; loc=document.location.href; url=loc.substring(0,loc.indexOf(":8080")); res=res.replace(/http\:\/\/localhost/g, url); document.location='data:text/html;charset:utf-8,' + res; </script>|;