/    Sign up×
Community /Pin to ProfileBookmark

Why does this function not work in IE?

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;
}
[/CODE]

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?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@scorpion0x17authorJan 28.2006 — :rolleyes: 29 views and nobody had the answer?

Oh well, I've fixed it now anyway.

The offending piece of code was this:

[CODE]
if(pathPage[0]=='/')
start=1;
[/CODE]


changed it to:

[CODE]
if(pathPage.charAt(0)=='/')
start=1;
[/CODE]


and it works. ?

Can anyone tell that I'm normally a C/C++ coder?
×

Success!

Help @scorpion0x17 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...