Page 1 of 1

Problem with code

Posted: Fri Mar 28, 2003 9:49 pm
by nigma
Hey I don't know why this would not work but it doesn't seem to:

Code: Select all

<SCRIPT language="JavaScript">

var width  = screen.width;
var height = screen.height;

if     ((width == 1280) && (height == 1024))
&#123;
	<?php
		$cooklife = time() + 1800;
		setcookie('res', '1280x1024', $cooklife);
	?>
	window.location="index1.html";
&#125;

</script>
Thanks for any help provided. It'sgreatly apreciated.

Posted: Sat Mar 29, 2003 12:10 am
by Malder
setcookie() defines a cookie to be sent along with the rest of the header information. Cookies must be sent before any other headers are sent (this is a restriction of cookies, not PHP).

Posted: Sat Mar 29, 2003 12:11 am
by nigma
See what I want to do is have a seperate stylesheet for each of the different resolutions. To do this I thought great idea, I would store there resolution in a cookie and then get the data from the cookie whereI would usually include the stylesheet. How else could I do this?

Posted: Sat Mar 29, 2003 6:52 am
by twigletmac
You can't mix PHP and JavaScript like that - PHP is server-side and has finished processing before the JavaScript even starts.

viewtopic.php?t=1030
viewtopic.php?t=7380&highlight=resolution+javascript

Why do you need a different style sheet for different resolutions?

Mac

Posted: Sat Mar 29, 2003 9:06 am
by Ben C
If you want to keep it similar to how it is, you'll have to do the whole thing in Javascript. If you don't know how to do cookies in Javascript see the advanced tutorial here:

http://hotwired.lycos.com/webmonkey/pro ... rial2.html

Hope this helps.

Posted: Sat Mar 29, 2003 12:49 pm
by nigma
Thanks a bunch. I really apreciate this.

Posted: Sat Mar 29, 2003 1:36 pm
by Ben C
I don't know if that is all of your code, or if you just pasted in a bit, but remember that Javascript should be 'commented out', so that at least in browsers that don't recognise Javascript, the code doesn't show on the visible page. Like this:

http://hotwired.lycos.com/webmonkey/98/ ... rogramming

Code: Select all

<script language="JavaScript"> 

<!-- hide this stuff from other browsers 

YOUR SCRIPT HERE 

// end the hiding comment --> 

</script>

Posted: Sat Mar 29, 2003 2:15 pm
by nigma
I had more code in there, but that was the section I was having trouble with.