therealwesfoster Posted December 4, 2007 Share Posted December 4, 2007 I have this code function doit() { var iframe = document.createElement("iframe"); iframe.id = "gf"; iframe.name = "gf"; iframe.frameborder = 0; iframe.style.top = '0px'; iframe.style.left = '0px'; iframe.height = '0px'; iframe.width = '0px'; iframe.style.position = "absolute"; iframe.style.display = "block"; iframe.scrolling = "auto"; iframe.src = "http://google.com"; window.document.body.appendChild(iframe); } It works in mozilla firefox, but doesn't work in IE.. help please Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 4, 2007 Share Posted December 4, 2007 it worked for me; I did it like this: <html><head></head><body> <script language="javascript"> function doit() { var iframe = document.createElement("iframe"); iframe.id = "gf"; iframe.name = "gf"; iframe.frameborder = 0; iframe.style.top = '0px'; iframe.style.left = '0px'; iframe.height = '400px'; iframe.width = '500px'; iframe.style.position = "absolute"; iframe.style.display = "block"; iframe.scrolling = "auto"; iframe.src = "http://google.com"; window.document.body.appendChild(iframe); } </script> <a href="javascript:void(0)" onclick="doit()">test</a> <body></html> Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted December 5, 2007 Author Share Posted December 5, 2007 It works for me too in firefox.. but in IE i get a popup error and it says this: Internet Explorer cannot open the internet site http://bla-bla.com/. Operation Aborted. And the error is coming from the iframe javascript file.. ??? confusing? why yes... yes it is Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted December 5, 2007 Share Posted December 5, 2007 It works for me in IE 6 with one exception, I had to add this to the function, because it wouldnt auto lookup google document.getElementById('gf').src = "http://www.google.com"; Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 5, 2007 Share Posted December 5, 2007 with one exception, I had to add this to the function, because it wouldnt auto lookup google document.getElementById('gf').src = "http://www.google.com"; now that does create an error message: document.getElementById('gf').src has no properties Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted December 5, 2007 Share Posted December 5, 2007 Thats strange, cause on all these browsers Mac-FireFox 2 Mac-Safari Mac-Opera Windows-FireFox2 Windows-IE6 Windows-Safari I get a nice frame with google showing up inside so here is the code so you can test what i tested <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <script language="javascript"> function doit() { var iframe = document.createElement("iframe"); iframe.id = "gf"; iframe.name = "gf"; iframe.frameborder = 0; iframe.style.top = '0px'; iframe.style.left = '0px'; iframe.height = '400px'; iframe.width = '500px'; iframe.style.position = "absolute"; iframe.style.display = "block"; iframe.scrolling = "auto"; //iframe.src = "http://www.google.com"; window.document.body.appendChild(iframe); document.getElementById('gf').src = "http://www.google.com"; } </script> <a href="javascript:void(0)" onclick="doit();">test</a> </body> </html> If your getting an error, i would check your script settings or run spybot or adaware Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted December 5, 2007 Author Share Posted December 5, 2007 ^ Alright thanks.. I will try that, i can see what you changed.. you "appended" the iframe BEFORE setting the SRC.. i was doing the opposite I will test it when I get home and let you know how that goes, thanks again Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 5, 2007 Share Posted December 5, 2007 Thats strange, cause on all these browsers Mac-FireFox 2 Mac-Safari Mac-Opera Windows-FireFox2 Windows-IE6 Windows-Safari I get a nice frame with google showing up inside so here is the code so you can test what i tested <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <script language="javascript"> function doit() { var iframe = document.createElement("iframe"); iframe.id = "gf"; iframe.name = "gf"; iframe.frameborder = 0; iframe.style.top = '0px'; iframe.style.left = '0px'; iframe.height = '400px'; iframe.width = '500px'; iframe.style.position = "absolute"; iframe.style.display = "block"; iframe.scrolling = "auto"; //iframe.src = "http://www.google.com"; window.document.body.appendChild(iframe); document.getElementById('gf').src = "http://www.google.com"; } </script> <a href="javascript:void(0)" onclick="doit();">test</a> </body> </html> If your getting an error, i would check your script settings or run spybot or adaware no, I do not have spyware or adware - have great software for that stuff; you just did not specify where to put your code. I was testing your code like; this: <script language="javascript"> function doit() { var iframe = document.createElement("iframe"); iframe.id = "gf"; iframe.name = "gf"; iframe.frameborder = 0; iframe.style.top = '0px'; iframe.style.left = '0px'; iframe.height = '400px'; iframe.width = '500px'; iframe.style.position = "absolute"; iframe.style.display = "block"; iframe.scrolling = "auto"; document.getElementById('gf').src = "http://www.google.com"; window.document.body.appendChild(iframe); } </script> that is why I was getting the error message. But again; the original code worked fine for me; when I tested it in IE7 & FF. Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted December 6, 2007 Author Share Posted December 6, 2007 Well i kept getting errors.. and then it stopped working all together.. lol, i dont know why but I recoded it to this and it works like magic <html> <head> <script language="JavaScript" type="text/javascript"> function makeFrame() { ifrm = document.createElement("IFRAME"); ifrm.setAttribute("src", "http://google.com/"); 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> Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted December 6, 2007 Share Posted December 6, 2007 just to followup: sorry, i assumed you would put line (1) after line (2) because you cant reference an object until it is instantiated (1) document.getElementById('gf').src = "http://www.google.com"; (2) window.document.body.appendChild(iframe); Man I hardly ever put JS in the header anymore, due to IE, In IE one main rule applies with JS, if the code is placed prior to the object, your lucky if it works ;-) Quote Link to comment Share on other sites More sharing options...
therealwesfoster Posted December 6, 2007 Author Share Posted December 6, 2007 Yeah, microsoft should put down their "pride" and have firefox as their default web browser.. but that will never happen.. thanks for the follow up though Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.