07-31-2023 04:02 AM
Hi folks,
Probably you have any idea about our current issue on updating the svg file using javascript.
WORKS:
- Modify HTML source in gweb </>
Adding the following texts:
<div id="svg1">
<object type="image/svg+xml" data="support/picture.svg" width="100%" height="100%">
</object></div>
Then in JS:
const svgObject = document.querySelector("#svg1 object");
const svgDoc = svgObject.contentDocument; //This give XMLDocument object.
DOES NOT WORK:
I used html container, create object element. The svg file is loaded.
However, I cannot access the contentDocument.
Object element creation:
const createSVG = function (container, svgPath) {
const svgObject = document.createElement('object');
svgObject.type = "image/svg+xml";
svgObject.data = svgPath;
svgObject.width = '100%';
svgObject.height = '100%';
container.appendChild(svgObject);
return svgObject;
};
Access document content as DOM file:
const svgDoc = svgObject.contentDocument; //This give HTMLDocument instead of XML document.
Any idea on how to resolve this as I need to modify the SVG during realtime (update sensor data based on its location in the image).
Solved! Go to Solution.
08-05-2023 06:43 PM
There are a lot of ways to approach this problem. I created an example that does the following approach:
08-05-2023 07:22 PM
Thanks a lot Milan. Really helpful. I will look into it.