How to make a button that calls an iframe

1

In% with% below, I need it only to be shown when I click on any button. How do I do this?

<div>
    <iframe
            width="1100"
            height="500"
            id="iframe"
            src="https://www.google.com.br"scrolling="no"
    </iframe>
</div>
    
asked by anonymous 19.10.2015 / 22:28

2 answers

1
  • Hide <iframe> with CSS ( display:none )
  • When you click the button, use javascript to display, as follows:

function exibirIframe()
{
    document.getElementById("iframe").style.display = "block";
}
#iframe {
    display: none;
}
<div>
    <iframe
            width="1100"
            height="500"
            id="iframe"
            src="https://www.google.com.br"scrolling="no">
    </iframe>
</div>
<input type="button" value="Exibir Iframe" onclick="exibirIframe();" />

Only one note : pages like google.com will not allow other domains to use it in iframes, per security account. This is done through the X-Frame-Options header sent by the server . I hope you've used this page as an example.

    
19.10.2015 / 22:59
1

If you want another alternative using jQuery, just include the jQuery code call and add this code snippet to the end of the code:

<script>
$(document).ready(function ()
{
    $('iframe').hide();
    $('button').click(function ()
    {
        $('iframe').show();
    });
});
</script>

I think the above code is self-explanatory, but if you need some help or explanation just call.

    
19.10.2015 / 23:09