1

I'm attempting to have a simple webpage where upon clicking a button, it will open up an excel worksheet that is on my desktop... Is my file path wrong? Or is it the wrong function call?

I've already tried a simple .open and now .location...

<!DOCTYPE html>
<html>
<body>

<p>This button will open Excel Sheet:</p>
<button type="button" onclick="myFunction()">This goes to the Excel Doc</button>
<script>
function myFunction() {
    window.location("C:\Users\jamiller\Desktop\spreadsheet.xlsx");
}
</script>
</body>
</html>

The button doesn't do anything, it should open the excel file

Joansj
  • 19
  • 1
  • 2
  • @Cyril (please don't call somebody's question bad if you won't explain how to make it better, it can be received as rude) ActiveXObject is only supported on IE, and presents security risks, hence why it wasn't standardized (besides being an MS extension) – Sterling Archer May 06 '19 at 17:10
  • In short, JS cannot access the computer. Methods are available, like a save URI, but these are workarounds. This is for security reasons (nobody wants a website to be able to open up excel, as this access would open security holes) – Sterling Archer May 06 '19 at 17:12
  • I attempted this solution in chrome to no avail, but in IE I was able to get it to open Excel but not the workbook I need - thanks though! – Joansj May 06 '19 at 17:16
  • @SterlingArcher i hope it was understood as *I am using electron fro developing an application in which I need to open the local excel file on button click so help me out with this*, being the scope of the question I linked being an ill-asked, poor-quality question, where I gave a link to a related answer to this question. That statement was not directed at OP's question; my apologies. Removed the comment as you explained the activex being related to the IE aspect. – Cyril May 06 '19 at 17:21
  • I would expect an error message like *window.location is not a function* – James May 06 '19 at 17:28

2 Answers2

0

You can't really "launch an application" in the true sense. You can as you indicated ask the user to open a document (ie a PDF) and windows will attempt to use the default app for that file type. Many applications have a way to do this.

For example you can save RDP connections as a .rdp file. Putting a link on your site to something like this should allow the user to launch right into an RDP session:

<a href="MyServer1.rdp">Server 1</a>

or

you can in Silverlight 4 (in out-of-browser with elevated full trust), example:

dynamic cmd = AutomationFactory.CreateObject("WScript.Shell");
cmd.Run("calc.exe", 1, true);
Joey Phillips
  • 1,543
  • 2
  • 14
  • 22
0

window.location is Object, it doesn't do what you want.. More information about window.location you can find here

If you want to open documents using Desktop Program, you should use protocol handlers. For Windows OS, place where you can find associations: Control Panel > Programs > Default Programs > Set Associations, Protocols

How to use it:

Example: ms-excel:ofv|u|https://contoso/Q4/budget.xls

BUT!

Command argument: a URI to the document, based on the http or https scheme

More examples...

You can add a link to your page with href attribute:

<a href="steam://rungameid/730">Run CS:GO</a>

This example will launch the Steam and run CS:GO

Or you can use this URI scheme to launch the Microsoft Store

ms-windows-store://navigatetopage/?Id=Games
DimaS
  • 37
  • 5