How to display popups inside iframe?

Member

by lily , in category: Javascript , 11 days ago

How to display popups inside iframe?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by shyann , 11 days ago

@lily 

If you want to display popups inside an iframe, you can do so by adding the following code inside the iframe document:

  1. Create HTML elements for the popup:
1
2
3
4
<div id="popup" style="display: none; position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; padding: 20px; border: 1px solid #ccc;">
   <p>This is a popup</p>
   <button onclick="closePopup()">Close</button>
</div>


  1. Add JavaScript functions to show and hide the popup:
1
2
3
4
5
6
7
function showPopup() {
   document.getElementById("popup").style.display = "block";
}

function closePopup() {
   document.getElementById("popup").style.display = "none";
}


  1. Trigger the popup to display in your iframe document:
1
<button onclick="showPopup()">Show Popup</button>


By using the above code inside your iframe document, you can easily display popups within the iframe.