How to open an iframe from clicking an image?

Member

by samara , in category: Third Party Scripts , 8 months ago

How to open an iframe from clicking an image?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by mac , 8 months ago

@samara 

To open an iframe from clicking an image, you can use the following HTML and JavaScript code:

  1. Create an image element with an onclick event handler that will open the iframe:
1
<img src="image.jpg" onclick="openIframe()">


  1. Create the iframe element that you want to open:
1
<iframe id="iframe" style="display: none;"></iframe>


  1. Write a JavaScript function that will show the iframe when the image is clicked:
1
2
3
4
function openIframe() {
  document.getElementById("iframe").style.display = "block";
  document.getElementById("iframe").src = "https://example.com"; // replace with the URL of the iframe content
}


  1. You can style the iframe using CSS or add any additional attributes as needed.


That's it! When you click the image, the iframe will be displayed with the specified content.

Related Threads:

How to hide an iframe after clicking?
How to open a iframe link within the same iframe?
How to force iframe open all links stay in the iframe?
How to open a page in iframe?
How to open a dialog outside the iframe?
How to force all links to open in iframe?