How to Run an External Program, E.G. Notepad, Using Hyperlink

How to run an external program, e.g. notepad, using hyperlink?

Try this

<html>
<head>
<script type="text/javascript">
function runProgram()
{
var shell = new ActiveXObject("WScript.Shell");
var appWinMerge = "\"C:\\Program Files\\WinMerge\\WinMergeU.exe\" /e /s /u /wl /wr /maximize";
var fileLeft = "\"D:\\Path\\to\\your\\file\"";
var fileRight= "\"D:\\Path\\to\\your\\file2\"";
shell.Run(appWinMerge + " " + fileLeft + " " + fileRight);
}
</script>
</head>

<body>
<a href="javascript:runProgram()">Run program</a>
</body>
</html>

Open an exe file through a link in a HTML file?

You can not start/execute an .exe file that resides locally on the users machine or through a site. The user must first download the exe file and then run the executable.

Idea's to launch an application (with parameters) from a pdf document

Action dictionary of Link annotation can have Win sub-dictionary with P key, containing "parameter string to be passed to the application". It looks like Acrobat is handicapped and doesn't allow to add/edit Win dictionary entries. You can use freeware PDF-XChange Viewer for that. E.g., I added a link to launch Notepad with a parameter, here's result (pretty-printed with mutool):

12 0 obj
<<
/A <<
/F 30 0 R
/S /Launch
/Win <<
/F (C:\\WINDOWS\\notepad.exe)
/O (open)
/P (/A c:\\boot.ini)
>>
>>
...

How to open link in a new tab in HTML?

Set the target attribute of the link to _blank:

<a href="#" target="_blank" rel="noopener noreferrer">Link</a>

For other examples, see here: http://www.w3schools.com/tags/att_a_target.asp



Note

I previously suggested blank instead of _blank because, if used, it'll open a new tab and then use the same tab if the link is clicked again. However, this is only because, as GolezTrol pointed out, it refers to the name a of a frame/window, which would be set and used when the link is pressed again to open it in the same tab.



Security Consideration!

The rel="noopener noreferrer" is to prevent the newly opened tab from being able to modify the original tab maliciously. For more information about this vulnerability read the following articles:

  • The target="_blank" vulnerability by example
  • External Links using target='_blank'


Related Topics



Leave a reply



Submit