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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Javascript file referencing

    Hi,

    I believe this is a simple problem however I am not the best at javascript.

    First of all I started with the following:
    Code:
    <a href="\\SERVER-01\folder\file.xls" target="_blank">
    however this opens the XLS file in a web browser.

    So I then created a function called "RunFile"

    so when I do the following it works fine:

    Code:
    <a href="#" onclick="RunFile('G:/Server/folder/file.xls');">Click me</a>
    However my problem is that the "G" drive is mapped. So when I try:
    Code:
    <a href="#" onclick="RunFile('\\SERVER-01\folder\file.xls');">Click me</a>
    it does not work. There is nothing wrong with the mapping so I am assuming I must have to use the "file://" prefix in some manner? I have tried various alternative to no avail.

    Regards,

    jmcall10

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    What code do you have in RunFile()
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,653
    Thanks
    80
    Thanked 4,640 Times in 4,602 Posts
    A backslash in a JavaScript string indicates that the next character designates some special meaning. e.g., \n means newline. \t means tab. And so on.

    This is true EVEN IF the character after the backslash is NOT special: In that case, the backslash is just ignored.

    So to actually *use* a backslash in a string, you must use TWO of them:
    Code:
    <a href="#" onclick="RunFile('\\\\SERVER-01\\folder\\file.xls');">Click me</a>
    As it was, your code was giving RunFile the string "\SERVER-01folderfile.xls"
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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