Loading and Unloading iframes with javascript


While working on miLock Pro I was looking for a way to load and unload iframes. 

Heres what I came up with.

  <script>
  
     function createTwitter()
             {
            iframe = document.createElement("iframe"); //create iframe
            iframe.id = "widget5"//name
            iframe.src="Widget/Twitter/LockBackground.html"; //location
            iframe.style.backgroundColor = "transparent"; //transbg
            iframe.frameBorder = "0"; //no border
            iframe.allowTransparency="true"; //allow trans
            d = document.getElementById("twitter"); //grab div to connect to iframe
            d.appendChild(iframe); //connect
            iframe = null;
            d = null;

        }

function removeIframe()
        {
            tweet = document.getElementById("widget5");
            tweet.src=""; //clear
            tweet = null; //clear
            var d = document.getElementById("twitter");
            d.removeChild(document.getElementById("widget5"));

        }
  </script>


Then call each function with either createTwitter() or removeIframe()

Not much to it really. Strange for the lack of documentation for this. Hope this helps someone.



No comments:

Post a Comment