figure containing uihtml with dynamic content loses dynamic content when resized.

1 次查看(过去 30 天)
It looks like the figures autoresize resets the innerHTML of a web page running inside uihtml.
After resizing the figure returns to its initial state (at start-up).
This demostrates the problem, click the button in the figure, then resize the figure.
Test.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Example of error</title>
</head>
<body>
<button onclick="TestCode()">Click for dynamic content</button>
<div id="div1">
<div/>
<script>
function TestCode() {
const para = document.createElement("h1");
const node = document.createTextNode("Some Content Here.");
para.appendChild(node);
const element = document.getElementById("div1");
element.appendChild(para);
}
</script>
</body>
</html>
function init()
uifig = uifigure("Name", "UI Window", "WindowStyle","normal",'NumberTitle','off');
uifig.Position = [500 500 1000 445];
uiView = uihtml(uifig);
uiView.Position = [10 10 980 420];
uiView.HTMLSource = "Test.html";
end

采纳的回答

Dinesh
Dinesh 2024-2-6
Hi Antony.
I'm unable to reproduce this behavior in R2023a.
Figure on startup:
Figure after clicking on the button 3 times:
Figure after resizing the window:
In your case, as I understand it, the dynamic content that was added disappears when the window resizes. Please let me know if my understanding is incorrect.
  1 个评论
Antony
Antony 2024-2-6
You are quite right, I double checked my code, I had one extra function in my version, which contained a typo.
It turns out that, if there is a small error in the JS when uihtml is initialized, then resizing will reset the div section of the DOM.
Good to know.
Thanks very much for helping me find this.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by