Announcement

Collapse
No announcement yet.

javascript and treatment of backslash

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    javascript and treatment of backslash

    I need to pass the value of the FragmentImageFileName to a javascript function and ran into a problem
    the image is in a subdirectory called "images" so I have an image name of
    images\racesuit.jpg
    when I then generate the code, it creates
    popItUp('../images\racesuit.jpg','the title')
    problem then is that Javascript treats the \r as a newline (regular expression) and I end up with
    <img src='../images
    acesuit.jpg'
    title='the title'>
    (note the new line, the missing \ and the missing r)

    the javascript I have is
    Code:
    function popItUp(url,title)
    	newwindow.document.writeln('<img src=' + url + ' title=\"' + title + '\" alt=\"' + title + '\" >');
    	}
    can anyone tell me how to remove the \r intepretation from the javascript - I've tried the javascript command of escape(FragmentImageFileName) but that doesn't work

    any ideas please

    #2
    I am definately not a Java syntax man however a couple of thoughts, which you may already have tried...
    1) enclosing the argument with a pair of " to force it to read it as a string

    Possible work-a-round?
    2) re-naming the image so that the first letter does not comply with regular expressions.

    Regards
    www.yandles.co.uk
    www.websilk.co.uk
    Today is the tomorrow that I worried about yesterday.
    So far, all is well. Am I still worried? YES! Watch some b.....d mess it up!

    Comment


      #3
      Use PHP to replace all backslashes with forward ones. E.g.

      Code:
      <actinic:block php="true">echo str_replace('\\','/','<actinic:variable name="myvar" encoding="perl" />');</actinic:block>
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        re-naming the image so that the first letter does not comply with regular expressions.
        not really practical, I choose to put the product images in a single subfolder to avoid duplicate file names, but I would now have to avoid anything beginning with R and N and ... and other regular expression letter

        Norman, thanks for the solution, I'll plug that in and play some more

        Comment

        Working...
        X