Solved

Create and populate iFrame onClick of a button?

Posted on 2016-10-12
1
64 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
ID: 41841267
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Read about why website design really matters in today's demanding market.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 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

21 Experts available now in Live!

Get 1:1 Help Now