//Replace the closeSelf() function in iframe page to the following function closeSelf() { parent.window.postMessage("removetheiframe", "*"); } //and on the parent page, add the following code to listen when the iframe sends a message : function receiveMessage(event){ if (event.data=="removetheiframe"){ var element = document.getElementById('iframe-element'); element.parentNode.removeChild(element); } } window.addEventListener("message", receiveMessage, false);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter