birdbrain

msg:4147324 | 11:36 am on Jun 5, 2010 (gmt 0) |
Hi there irock, I prefer to use DOM methods rather than document.write. ;) It seems that it is only IE that will not render the "onload" So the only work-around that I could think of for that browser was setTimout() Here is my code... <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <meta http-equiv="Content-Script-Type" content="text/javascript">
<title>untitled document</title>
<script type="text/javascript">
function init(){
cnetproductname='Buffalo'; id='32432443'; type='reviews';
f=document.createElement('iframe'); f.setAttribute('id','myFrame'); f.setAttribute('frameborder',0); f.setAttribute('scrolling','no'); f.setAttribute('width','100%'); f.setAttribute('src','http://www.domain.com/grab.php?productname='+ cnetproductname+'&id='+id+'&type='+type+'&embed="0"');
f.setAttribute('onload','adjustMyFrameSize()'); [red]/*IE returns "undefined" for "onload" */[/red]
document.getElementById('iframe-container').appendChild(f);
if(isIE=/*@cc_on!@*/false){ setTimeout(function(){adjustMyFrameSize()},5000); } }
function adjustMyFrameSize(){ alert('function adjustMyFrameSize is initiated') }
if(window.addEventListener){ window.addEventListener('load',init,false); } else { if(window.attachEvent){ window.attachEvent('onload',init); } }
</script>
</head> <body>
<div id="iframe-container">
</div>
</body> </html>
|
| Also note that the id selector should never start with a number. It may well work in javascript coding but will fail in CSS. birdbrain
|
irock

msg:4147403 | 5:05 pm on Jun 5, 2010 (gmt 0) |
WOW... I didn't expect someone to provide me with a complete fix. I will try that now. Thanks man.
|
birdbrain

msg:4147409 | 5:18 pm on Jun 5, 2010 (gmt 0) |
No problem, you're very welcome. ;)
|
irock

msg:4147453 | 6:55 pm on Jun 5, 2010 (gmt 0) |
Thanks birdbrain, I'm sorry, but how do I print out the result? Do I have to put something inside to make this work? Sorry for asking a dumb question. <div id="iframe-container"> </div>
|
birdbrain

msg:4147462 | 7:19 pm on Jun 5, 2010 (gmt 0) |
Hi there irock, | Sorry for asking a dumb question. |
| It's not a dumb question but I do not really sure that I understand it. ;) I'm sorry, but how do I print out the result? Do I have to put something inside to make this work? Sorry for asking a dumb question. |
| To make it work just "Copy & Paste" the code into Notepad and save as an HTML file. birdbrain
|
JAB Creations

msg:4148695 | 7:56 am on Jun 8, 2010 (gmt 0) |
Whoa, WHOA! Don't use document.write EVER! Using the script element as a child to the body element is exceptionally poor practice. Using document.write which is not a standard (and no, even if they did add it to a standard it's still a heaping pile of...bad) is the quickest way to go jump off a thousand foot cliff with JavaScript. To write a string of text to an element try the following... XHTML
<span id="target_span"> </span> JavaScript
document.getElementById('target_span').firstChild.nodeValue='Hi Mom!'; Keep in mind that if the span does not contain a string (including even an empty space) browsers will have difficulty with this. - John
|
L33t_J0rdan

msg:4153428 | 7:29 am on Jun 16, 2010 (gmt 0) |
Thanks for the explanation, John. Looks like I'm not going to be using document.write anymore!
|
|