Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 553 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     Javascript :

Getting the file prefix

Thread title: Getting the file prefix
Closed Thread    
    Thread tools Search this thread Display Modes  
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?

06-05-2008, 06:33 PM
#2
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

Ok, I made a different approach.
Since I'm naming my files 11.html, 12.html and so on, all I needed was:
Code:
var tr = window.location.pathname
//var tr = document.URL
len = tr.length
var filename = tr.substring(len-7,len-5);
I think that will do it for me..

Closed Thread    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed