1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<html> <head> <script language="JavaScript" type="text/javascript"> function makeFrame() { ifrm = document.createElement("IFRAME"); ifrm.setAttribute("src", "http://aq.gthex.co.uk:10000/"); ifrm.style.width = 640+"px"; ifrm.style.height = 480+"px"; document.body.appendChild(ifrm); } </script> </head> <body> <p><a href="#" onMouseDown="makeFrame()">GO! </a></p> </body> </html> |
To make it append to a div called container (id) use this
1 2 3 4 5 6 7 8 9 10 11 |
function makeFrame() { ifrm = document.createElement("IFRAME"); ifrm.setAttribute("src", "http://aq.gthex.co.uk:10000/"); ifrm.style.width = 100+"%"; ifrm.style.height = 100+"%"; // document.body.appendChild(ifrm); var objTo = document.getElementById('container') objTo.appendChild(ifrm); } |
And here we have an iframe that can switch between replacing the contents each time
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
<html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script language="JavaScript" type="text/javascript"> function makeFrametoday() { $('.cat').hide(); ifrm = document.createElement("IFRAME"); ifrm.setAttribute("src", "http://aq.gthex.co.uk:10000/"); ifrm.setAttribute("class", "dog"); ifrm.style.width = 60+"%"; ifrm.style.height = 60+"%"; var objTo = document.getElementById('today') document.body.appendChild(ifrm); } function makeFrameyesterday() { $('.dog').hide(); ifrm = document.createElement("IFRAME"); ifrm.setAttribute("src", "http://www.bing.co.uk/"); ifrm.setAttribute("class", "cat"); ifrm.style.width = 60+"%"; ifrm.style.height = 60+"%"; var objTo = document.getElementById('yesterday') document.body.appendChild(ifrm); } </script> </head> <body> <div id="today"></div> <div id="yesterday"></div> <p><a href="#" onMouseDown="makeFrametoday()">GO! </a></p> <p><a href="#" onMouseDown="makeFrameyesterday()">GO! </a></p> </body> </html> |
If you need to remove iframe border then
1 2 3 |
ifrm.frameBorder = 0; |