Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jan 2005
    Location
    West Midlands, United Kingdom
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question *help* reading a filename using javascript

    hey peeps,

    i'm currently looking at getting a script to read in a filename and select a style sheet for the page depending on the name.

    so for example "blue_fish.gif" brings up a blue style or "red_herring.gif" brings a red style up.

    One way which works is setting up two arrays one with the images loaded in and one with the css files in. however i'm finding it very messy especially when i want to update more pictures and add more styles.

    so i was wondering if there is some way i can just look at the filename and then pick a style.

    regards,

    Al.

  • #2
    Senior Coder
    Join Date
    Dec 2004
    Location
    Essex, UK
    Posts
    2,636
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well you can use Javascript to switch styles if that's what you need?

    http://www.google.co.uk/search?hl=en...switcher&meta=

  • #3
    New Coder
    Join Date
    Jan 2005
    Location
    West Midlands, United Kingdom
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well hmm,

    well i want the sheet to change depending on the name of an image.

    So i'm wondering if i could parse the file name somehow, perhaps trying to do a hack job on the javascript cookie methods.

    hope that clears it up a little,


    AL.

  • #4
    Senior Coder
    Join Date
    Feb 2004
    Location
    Edinburgh
    Posts
    1,352
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mr_Al
    well i want the sheet to change depending on the name of an image.
    and on what event do you want this to happen?
    *keep it simple (TM)

  • #5
    New Coder
    Join Date
    Jan 2005
    Location
    West Midlands, United Kingdom
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i guess this would trigger when a user clicks a link to a specific section, i can see where you're going to with this tell me if i'm gone in the wrong direction, by setting it to change on an onClick() event, changing picture and stylesheet....at the same time..?

    But i'm after something like the filename parser to make things simpler for a person to update. Meaning i'm not the only one updating the site i'm working on and i would like to make things easier for the other people putting stuff up. A simple rename this file to say BLU_main.jpg to bring a bluestyle sheet up would be superb to both myself and the people working with this.

    i understand this would be a hell of a lot easier with php, but i don't have the luxury of a php, apache server. So i'm doing it old school... despite it being slow .


    hope that hasn't confused you...

    regards,

    Al.

  • #6
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    If you are triggering it onclick, don't you already have to know what stylesheet to put there?
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #7
    New Coder
    Join Date
    Jan 2005
    Location
    West Midlands, United Kingdom
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i would like it to change it automatically, so when you load a page with a BLU_ in the image name in it picks the sheet like that. instead of setting it to change the sheet for each link and behaviour.

    regards,

    Al.

  • #8
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    so is this blue image constantly changing to a different image? Is it some type of random image script?

  • #9
    New Coder
    Join Date
    Jan 2005
    Location
    West Midlands, United Kingdom
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i don't want it to just do blue images also want to set the styles to different schemes; red for a RED_img, green for a GRE_img, yellow for a YEL_img.

    A random image would be nice, but i know that javascript won't populate arrays based on a file's contents. Hmmm would be nice that, then you could get it to just pick an image, then feed the img name into another script that picks up the tag... or use two arrays mirroring a style sheet with an image... [1]BLU_img --> second array--->[1]Blue.css, however this is easy for me..but for other folks..might be daunting .

    i just don't know what to do anymore

    ..would be so much easier leaving it at a switch on click wouldn't it...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •