Hide iFrame using javascript

0
Hi , Is it possible to hide an iFrame by using javascript when content of iFrame get changed or if we get callback url in iFrame? In my scenario I have iFrame loaded with URL and once submitted we get call back. I need to hide Iframe and show another mendix container with Success message. 
asked
1 answers
0

Hi Shriram Patil

Here is below code add in JavaScript function and replace "your-iframe-id" with your id of I Frame

// Listen for changes in the iFrame's content window.addEventListener('load', function() { var iframe = document.getElementById("your-iframe-id"); iframe.addEventListener('content-changed', function() { // Hide the iFrame iframe.style.display = "none"; // Show another Mendix container with a Success message // Assuming you have a div with id "success-message" var successMessage = document.getElementById("success-message"); successMessage.style.display = "block"; }); }); // Listen for the callback URL window.addEventListener('message', function(event) { if (event.data === "callback-url-received") { // Hide the iFrame iframe.style.display = "none"; // Show another Mendix container with a Success message // Assuming you have a div with id "success-message" var successMessage = document.getElementById("success-message"); successMessage.style.display = "block"; } });

I hope this will help.

 

answered