March 3, 2012

how to open a page and force an iframe load?

Question by Lucas Matos

I would like to know is it possible to, when clicking a link, open a main page and force to load another page in a frame inside the main page?

Any idea?

Answer by Starx

Include the following js script on the main page and you are done

function loadframe(){
  var i = document.getElementById("iframeID");
  i.src = "path/to/file";
};

// Check for browser support of event handling capability
if (window.addEventListener)
    window.addEventListener("load", loadIframe, false);
else if (window.attachEvent)
    window.attachEvent("onload", loadIframe);
else window.onload = loadIframe;

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!