I'm currently trying to create a navigation system for a website I'm creating. I spent hours trying to figure this out, but i dont understand why its not working I'm trying to replace all occurrences of "index.html" with the variable filenames.
function changeSideNav(filenames)
{
var urlarray = window.location.href.split("?");
var url = urlarray[0];
alert(url); // This returns "http://localhost/xxx/index.html"
var urlspl = url.replace(/index.html/gi,filenames);
alert(url.replace(/index.html/i,filenames) +'/'+ filenames); //This returns "http://localhost/xxx/index.html/newpage.html" (if pram was newpage.html).
//i txpected it to return "http://localhost/xxx//newpage.html"
//set a new source
document.getElementById('SideNavIframe').src = urlspl +'/'+ filenames;
}
Edit: i find this to be strange: if i try to replace "/index.html" instead of "index.html", it removes the "/" from the output so i get "http://localhost/xxxindex.html/newpage.html".
url.replace("/index.html", filenames)?alert(filenames)to be sure you know everything that's going on.