JS- displaying different images according to res

All web design questions, hints and solutions can be discussed here.

Moderators: fac51, 117, Chris

Post Reply
vinnieza
Allowed to Drink!!!!
Posts: 3258
Joined: Sun Mar 07, 2004 12:09 pm
Location: Pluto
Contact:

JS- displaying different images according to res

Post by vinnieza »

Hi, How do you display images in the document.write() comand using javascript? I have this but it doesn't appear to be working:

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
var correctwidth="800"
var correctheight="600"
if (screen.width<=correctwidth||screen.height<=correctheight)
document.write("<img src="l_navigation_img.jpg">")
else
document.write("<img src="navigation_img.jpg">")
</SCRIPT>


Or isn't it possible?

Edit: I have this, but it doesn't seem to be working? any ideas why? missing ";"?

Code: Select all

<SCRIPT LANGUAGE="JavaScript">
var correctwidth="800"
var correctheight="600"
var nav_l = new Array ("l_navigation_img.jpg")
var nav_b = new Array ("b_navigation_img.jpg")
if (screen.width<=correctwidth||screen.height<=correctheight)
document.write("<img src="+nav_l+">")
else
document.write("<img src="+nav_b+">")
</SCRIPT>


Nevermind, i think i now have it, i put +nav_b_b+ and that's not a variable :oops:, noticed it when posting it here :)
Image
....................My site: www.vthemes.co.uk
.........................* no questions asked *

Image
vinnieza
Allowed to Drink!!!!
Posts: 3258
Joined: Sun Mar 07, 2004 12:09 pm
Location: Pluto
Contact:

Post by vinnieza »

Instead of makin new arrays and using "+tag+" is there another way of doing it? for example could i use, like using single quotes or somthing like that?
Image
....................My site: www.vthemes.co.uk
.........................* no questions asked *

Image
Post Reply