View Full Version : Javascript file referencing

11-09-2012, 04:27 AM

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

First of all I started with the following:

<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:

<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:

<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.



11-09-2012, 10:23 PM
What code do you have in RunFile()

Old Pedant
11-10-2012, 12:18 AM
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:

<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"