I want to replace “http://” “https://” “www.” and also explode the url on “/”.
For example: http://www.google.com/whatever should return google.com
I was doing as much as I knew how on this function:
// Change site's title
function changeTitle(url) {
var title = url.replace("http://", ""); // 1
title = title.replace("https://", ""); // 2
title = title.replace("www.", ""); // 3
document.title = title;
}
But I want to do all the process on a separate function, e.g: function cleanUrl(url). I tried this and variants but couldn’t make it work:
// Clean URL
function cleanUrl(url) {
var title = url.replace("http://", "");
title = title.replace("https://", "");
title = title.replace("www.", "");
}
// Change site's title
function changeTitle(url) {
cleanUrl(url);
document.title = title;
}
How do I do it? Also I’m not exploding the url since I didn’t know how.
1 Answer