1

Gang,

I'm hoping someone can tell me what I'm doing wrong here. I've searched several places and everything I'm doing should be working, but it's not. I have a page on a local company intranet. When someone clicks a checkbox for a category with a related document, the page should open up a file (usually a .docx or .xlsx) from the network shared drive. I put in an alert message to make sure it was passing through that part of the function. That works, but nothing happens after that. Here's the function and here's how I'm calling it.

<script type="text/javascript"> 
function opensupport(chkbox, url) {
    var x = document.getElementById(chkbox)
    if (x.checked) {        
        if (confirm(x.value + " has an associated document to complete.  Would you like to open that now?")) {
            alert("opening " + url);
            window.open(url, 'newwin');
        } 
    }
}

Here's how I'm calling it...

<input type='checkbox' name='initiative' id='34' value='Test Link' onclick="opensupport('34', 'file:\\qdcns0001\projects\EAI Vendor Management\fact sheets\docs\AdvancedMD_Fact_Sheet.doc')"/>
kidcosmo
  • 21
  • 1
  • 3
  • AFAIK URLs use forward slashes, even if you are on Windows. Even if the directory separators should be backslashes (which I doubt) the protocol part of a URL should use a double _forward_ slash. I suspect the browser simply can't parse the URL and hence refuses to open the window. – 11684 Jul 03 '14 at 16:45
  • Check this: [http://stackoverflow.com/questions/5796215/an-url-to-a-windows-shared-folder](http://stackoverflow.com/questions/5796215/an-url-to-a-windows-shared-folder) – peter_the_oak Jul 03 '14 at 16:49
  • Have you seen this: http://stackoverflow.com/questions/3582671/how-to-open-a-local-disk-file-with-javascript – An Phan Jul 03 '14 at 16:49
  • Gah!! It's always the simplest things that I overlook. That worked when I replaced the "\" with "/". – kidcosmo Jul 03 '14 at 16:52

2 Answers2

1

In a Javascript string literal the backslash is the escape character. You need to use double backslashes to get a backslash in a string:

'file:\\\\qdcns0001\\projects\\EAI Vendor Management\\fact sheets\\docs\\AdvancedMD_Fact_Sheet.doc'

As user 11684 pointed out, an URL normally uses slashes, not backslashes, so that wold be:

'file://qdcns0001/projects/EAI Vendor Management/fact sheets/docs/AdvancedMD_Fact_Sheet.doc'

Also, you may need to URL encode the spaces in the URL. Although most browsers are very lenient about this, an URL according to the standards may not contain spaces.

'file://qdcns0001/projects/EAI%20Vendor%20Management/fact%20sheets/docs/AdvancedMD_Fact_Sheet.doc'
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

You need to escape the slashes

file://///qdcns0001\projects\EAI Vendor Management\fact sheets\docs\AdvancedMD_Fact_Sheet.doc
David Pullar
  • 706
  • 6
  • 18