Solved

Create and populate iFrame onClick of a button?

Posted on 2016-10-12
1
43 Views
Last Modified: 2016-10-12
Is it possible to create and populate a 40px x 40px iFrame that loads google.com on the click of a button? The iFrame can not exist until the button is clicked. NO JQuery please.

Thanks!
0
Comment
Question by:894359
1 Comment
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 500 total points
Comment Utility
you can try below:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>

</title></head>
<body>
    <form method="post" action="" id="form1">
    <div>
        <input id="Button1" type="button" value="button" onclick="generateIFrame()" />
        <br />
        <br />
        <br />
        <div id="test"></div>
    </div>
    </form>
</body>
</html>

<script>
    function generateIFrame() {
        var iframe = document.createElement('iframe');
        iframe.frameBorder = 0;
        iframe.width = "40px";
        iframe.height = "40px";
        iframe.id = "iframe1";
        iframe.setAttribute("src", "http://www.w3schools.com/");
        document.getElementById("test").appendChild(iframe);
    }
</script>

Open in new window

few things to be concerned:
1. 40px x 40px is relatively small
2. we cannot put google.com in iframe.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now