When running a Matlab web App, how do I run cleanup code upon the browser tab closing?

5 ビュー (過去 30 日間)
Eyal Doron
Eyal Doron 2025 年 4 月 28 日
コメント済み: Eyal Doron 2025 年 5 月 29 日
I have compiled an App Designer app to run as a web app in a browser, using the Matlab Web App Server. When running a normal app, one can put cleanup code in the FormClosing callback, such that it runs when the app is closed. However, closing a web app tab in a browser does not call this callback. Is there a way to have Matlab code run automatically when the app tab is closed?

回答 (1 件)

Sreeram
Sreeram 2025 年 5 月 5 日
Hi Eyal,
I understand that the "CloseRequestFcn" which is properly triggered when running an app in MATLAB, does not get triggered when the app is deployed as a web app and closed in the browser.
It is a documented limitation that the "CloseRequestFcn" property has not effect in web apps:
As a potential workaround, you can register a "DeleteFcn" callback for your "uifigure", which will be called whenever the web app is closed. To do this, add the following line to "startupFcn":
app.UIFigure.DeleteFcn = createCallbackFcn(app, @deleteFcn, true);
and then create a function called "deleteFcn" in your app like this:
function deleteFcn(app, event)
% put your logic here that would otherwise be in CloseRequestFcn
end
I hope this workaround helps!
Best regards,
Sreeram

カテゴリ

Help Center および File ExchangeMATLAB Web App Server についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by