Search code examples
matlabhyperlinkmatlab-compiler

Hyperlink causes compiled MATLAB application to crash


I have a compiled matlab application, which has a gui. This gui also contains a webpage within it, index.html. In the html, there is a hyperlink to a website. I want matlab to load the webpage in an external browser when this link is clicked. currently, this is the hyperlink I use:

<a href="matlab:web('http://www.google.com','-browser')">Help</a>

However, when clicked, the compiled program crashes and closes immediately. This does NOT happen when I start the program from within matlab; in this case it works as expected (and wanted). The effect is only present when the application is compiled. Why is this? Is there any way to fix it?

EDIT: here is a a simple verifiable example, etc.

first the simple matlab code:

% Create a blank figure window
f=figure('Name','Browser GUI Fail','Units','norm');

% Add the browser object
com.mathworks.mlwidgets.html.HTMLRenderer.setUseWebRenderer(false);
jObject = com.mathworks.mlwidgets.html.HTMLBrowserPanel;
[browser,container] = javacomponent(jObject, [], f);

set(container,'Units','normalized','Position',[0 0 1 1 ]);
url=['file:/'  which('index.html') ];
browser.setCurrentLocation(url);

second, the html file, index.html

<!DOCTYPE html>
<html>
<body>

<p>stuff, anything at all <a href="matlab:web('http://www.google.com','-browser')">Help</a> </p>

</body>
</html>

The link fails in the compiled version of the program. I am on Windows, and using 2014b.


Solution

  • I had a similar problem in a Windows compiled GUI and I solved it using a dos call.

    dos('start http://www.google.com');