3

I found this code in the accepted answer here... which loads an iframe into a specific area via a button click...

<a href="#" onclick="setIframe(this,'http://www.stackoverflow.co.uk')" >Set the Iframe up</a>

function setIframe(element,location){
    var theIframe = document.createElement("iframe");
    theIframe.src = location;
   element.appendChild(theIframe);
}

how do I change this so that it allows me to style the height width and scrolling?

Community
  • 1
  • 1
Sun Rhythms
  • 55
  • 1
  • 7

2 Answers2

2
theIframe.style.*

Any Property Which You want to style.

Muhammad Talha Akbar
  • 9,952
  • 6
  • 38
  • 62
2

This is not jQuery, but pure Javascript:

function setIframe(element,location){
    var theIframe = document.createElement("iframe");
    theIframe.src = location;
    theIframe.setAttribute("weight", "500");
    theIframe.setAttribute("width", "500");
    theIframe.setAttribute("scrolling", "yes");
    element.appendChild(theIframe);
}

This is not part of your question, but here is how you toggle a div with jQuery:

Markup:

<input type="button" value="Toggle Div"  id="btnToggle"/>

    <div id="randomContent">
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
        This is random Content.
        <br />
    </div>

jQuery:

    $(document).ready(function () {
        $("#btnToggle").bind("click", function () {
            $("#randomContent").toggle();
        });
    });
Hanlet Escaño
  • 17,114
  • 8
  • 52
  • 75
  • what if I don't want to or "shouldn't" put into an iframe but I want the div to toggle hide and revealed based on two different buttons... i asked a separate question on stackoverflow... will post link shortly – Sun Rhythms Feb 01 '13 at 17:08
  • thnx for that... here is the link. There are two buttons. one to submit the form and then another one for revealing of the form. http://stackoverflow.com/questions/14651706/how-to-hide-form-on-submit-and-reveal-it-on-a-button-click – Sun Rhythms Feb 01 '13 at 17:25