View Single Post
06-03-2008, 10:32 AM
#1
G-Sun is offline G-Sun
Status: Member
Join date: Feb 2008
Location: Norway
Expertise:
Software:
 
Posts: 101
iTrader: 0 / 0%
 

G-Sun is on a distinguished road

  Old  Getting the file prefix

Hi!
I'm a newbie on Javascript.
I'm trying to get the filname prefix to manipulate some links.
I can't seem to get it right..

Code:
//This works fine
var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) {OSName="Windows"};
if (navigator.appVersion.indexOf("Mac")!=-1) {OSName="MacOS"};
if (navigator.appVersion.indexOf("X11")!=-1) {OSName="nix"};
if (navigator.appVersion.indexOf("Linux")!=-1) {OSName="nix"};

//This is the problem
var url = document.URL;
var filename="Unknown filename";
if (OSName == "nix") {
filename = url.substring(url.lastIndexOf("\/")+1,url.length-5; // for *nix
}
else {
filename = url.substring(url.lastIndexOf("\\")+1,url.length-5; // for windows 
}

// For testing if I'm getting it right..
document.write(OSName);
document.write("<br />");
document.write(filename);
I seem to miss a statement for OS = Mac . Is it the same as *nix, windows or something else?