Reputation: 1
I am working on integrating the Draw.io editor into my custom web application, which is based on html css js. As a data modeler, I know little javascript. I have successfully embedded Draw.io in an iframe and can interact with it to some extent. However, I need help retrieving the designed ERD diagram's XML data from the canvas and passing it back to my application for further processing and generate SQL DDL script from ERD model. But I am unable to do that and here is my current situation:
Hosting Environment:
I have deployed the Draw.io editor on my own server using Tomcat, with NGINX as a proxy. The application is accessible via this URL:
https://app.flingex.com/draw/
Integration with Web App:
I have embedded the Draw.io editor in an iframe on one of my Web Application using the following code:
<iframe
id="drawio_iframe"
src="https://app.flingex.com/draw/"
style="width: 100%; height: 500px;">
</iframe>
Objective:
I want to retrieve the clean XML data of the diagram designed in the Draw.io editor via the iframe using postMessage
. The XML data will then be stored in the database for further manipulation and generate SQL DDL script from ERD model .
Sending postMessage
to the Iframe
I used the following JavaScript to send a message to the iframe:
const iframe = document.getElementById('drawio_iframe');
iframe.contentWindow.postMessage(
{ action: 'export', format: 'xml' },
'https://app.flingex.com'
);
Listening for Messages in the Iframe
I opened the iframe directly in a new tab (https://app.flingex.com/draw/
) and added this listener to debug:
window.addEventListener('message', function(event) {
console.log('Message received:', event);
});
Results:
postMessage
seems to send successfully, but I don’t see any response or XML data being returned to my application.{ action: 'export', format: 'xml' }
to the iframe, I expect the iframe to respond with the exported XML data from the Draw.io canvas.postMessage
events for exporting XML data?embed=1
in the iframe URL, as I want to keep the design tools visible.https://app.flingex.com/draw/
works fine when accessed directly.I’m looking for guidance on how to properly implement the following:
postMessage
or another method).I appreciate any help or suggestions to solve this issue. Let me know if you need more details or access to any specific code snippets.
draw.io
iframe
postmessage
javascript
html
Upvotes: -2
Views: 33