Issues Getting And Regex'ing A Url

Jan 9, 2006

Basically i want to get the current url, and then replace http:// with
something else.

Here is the current code.

var current_url = window.document.location;
var re = new RegExp("http://", "g");
if(re.test(current_url)) {

me = current_url.replace(re,"http://www.addme.com/");

window.alert("found :: " + me + " :: " + current_url);
} else {
window.alert("not");}

if my page was http://ww.google.com 'd get the alert to be:

found :: undefined :: http://www.google.com.

I dont understand why i am getting undefined. When re.test() works.
surely that means the regex is correct.

View 14 Replies


ADVERTISEMENT








Copyrights 2005-15 www.BigResource.com, All rights reserved