Hi, can anyone tell me why the following function doesn’t work correctly in IE?
[CODE]
function BuildRootPath(pathPage)
{
//alert(“BuildRootPath(“+pathPage+”)”);
// add one ‘../’ per ‘pathpart/’ except root ‘/’ //
var pathRoot=”;
var start=0;
// skip root //
if(pathPage[0]==’/’)
start=1;
// add one ‘../’ per ‘pathpart/’ //
var end=pathPage.indexOf(‘/’, start);
while(end!=-1)
{
pathRoot+=’../’;
start=end+1;
end=pathPage.indexOf(‘/’, start);
}
return pathRoot;
}
Basically, it should, for a given path, construct the reverse path back to the root directory.
For example, if I pass in “/dir1/dir2/dir3/page.html” it should return “../../../” – which it does in FireFox, but not in IE (v6) – in IE it returns “../../../../”. 😡
What am I doing wrong?