Forum Moderators: open

Message Too Old, No Replies

using document.write to load iframe

for beginners

         

Powdork

5:18 am on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am trying to load an iframe where the source and size are dependent upon the screen resolution. Here is the code that doesn't work

<script language='JavaScript' type='text/javascript'>
<!--
var feature = "large.htm";
if (screen.width <= 1025) feature = "small.htm";
document.write ("<iframe src =(feature)>
<p>Your browser does not support iframes.</p>
</iframe>");
//-->
</script>

daveVk

5:54 am on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



document.write ("<iframe src =" + feature + " >
<p>Your browser does not support iframes.</p>
</iframe>");

Powdork

6:00 am on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks, but still doesn't work

daveVk

7:13 am on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try without newlines between quotes

document.write ("<iframe src =" + feature
+ " ><p>Your browser does not support iframes.</p>"
+ "</iframe>");

No a fan of document.write, I assume this code is inline within the body ?

What sort of error indication do you get ?

Powdork

7:29 am on Nov 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that did the trick.
it is inline. i had it all in the body, but now the variable declaration and screen res change is in the head, with the document.write in the body. it should work either way i guess.