Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

resolution sniff for table background image 1

Status
Not open for further replies.

boyfromoz

Technical User
Joined
Feb 1, 2001
Messages
469
Location
AU
I've used a javascrtipt reolution sniff to load a particular image depending on resolution.

See below

<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot;>

if (screen.height >= 768 && screen.width >= 1024) {
document.write(&quot;<img src='webimages/tableopener/largeopen.gif' width=900 height=380 border=0>&quot;);
}
else {
if (screen.height == 600 && screen.width == 800) {
document.write(&quot;<img src='webimages/tableopener/mediumopen.gif' width=700 height=289 border=0>&quot;);
}
else {
document.write(&quot;<img src='webimages/tableopener/smallopen.gif' width=550 height=222 border=0>&quot;);
}
}
// End -->
</script>

Can this be modified somehow so it can be used to set the background image of a table cell, depending on the resolution?

 
Wrap your script code into some function:

function writeBgr() {

if (screen.height >= 768 && screen.width >= 1024) {
document.write(&quot;<td background='webimages/tableopener/largeopen.gif'>);
}
else {

. . .
document.write(&quot;<td background='webimages/tableopener/smallopen.gif'>);
. . .
}


Then call it like this:

. . .
<tr>
<script>writeBgr();<script>cell content</td>
<td>another cell</td>
</tr>
. . .

The highlighted part will be substituted by this:
<td background=&quot;script_selected_image&quot;>
 
ta

figured as much, my avascript is limited to cut and apste, + manipualte a bit, so give given me the sytax to write in now.

Good show.

 
Ahh... No... Can't get it it to work, keep getting sytnax errors. Even tried simplifying it by taking out the function as shown below

<!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot;>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>

<body>
<p>&nbsp;</p>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<SCRIPT>
if (screen.width>=835){
document.write(&quot;<td background='webimages/backgrounds/homelarge.jpg'>&quot;);
}
if {screen.width>=740 & w<835){
document.write(&quot;<td background='webimages/backgrounds/homemedium.gif'>&quot;);
}
if {screen.width<740){
document.write(&quot;<td background='webimages/backgrounds/homemedium.gif'>&quot;);
}
}
// End -->
</script><p>sdfsdfsdf</p>
<p>sdfsdfsdf</p></td>
</tr>
</table>
<p>&nbsp;</p>
</body>
</html>

I can't figure out what I have done wrong?
 
Correct all your errors:

if {screen.width>=740 & w<835){

& should be &&
What is w? It is not defined anywhere.

That's what I found right now, but there are probably more.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top