application.showURL() also does not work anymore on Windows Server 2019.
We have found that application.executeProgram() is a better alternative even for opening URL's in smartclient. application.showURL() is only usable in NG client when you want to open new tab or redirect.
If you're using svyUtils there is this method in scopes.svyIO which covers al os'es and will also work with URLs and mailto: links. Or else just copy the code and adjust to your needs.
- Code: Select all
function openFileWithDefaultViewer(file) {
// TODO: Support opening in the WC: either plugins.file.writeFile, but required to read the content first or showUrl, if file is accessible from the outside (see deprecated globals.svy_utl_open_file())
// TODO: test Linux support: SampleCode suggests using xdg-open here: https://www.servoy.com/forum/viewtopic.php?f=15&t=15237&p=81646&hilit=application+getosname+and+linux#p81653
// TODO param {String} [mimeType] Required for usage in the Web Client. Used by the browser to determine how to open the file
if (!scopes.svySystem.isSwingClient()) {
throw new scopes.svyExceptions.UnsupportedOperationException('Operation only supported in Smart or Runtime Client');
}
var osName = application.getOSName();
/** @type {String} */
var filePath = file;
if (file instanceof plugins.file.JSFile) {
filePath = file.getAbsolutePath();
}
if (/Windows/.test(osName)) {
application.executeProgram('rundll32', ['url.dll,FileProtocolHandler', filePath]);
} else if (/Linux|Freebsd/.test(osName)) {
application.executeProgram('mozilla', [filePath]);
} else if (/Mac/.test(osName)) {
application.executeProgram('open', [filePath]);
}
// What if no match?
}