Forum Moderators: coopster

Message Too Old, No Replies

PHP check: Is Javascript enabled?

         

Will Hamilton

9:32 pm on Jul 26, 2006 (gmt 0)

10+ Year Member



My site has a scaleable banner that uses Java to fit the user's screen - one for 800px width and another for 1024px. This does however mean that the banner doesn't display at all if the user has javascript disabled.

I want to do a simple check in php in order to find if javascript is on or not; from there I can run ifs and elses easily. I'm sure this should be quite a simple function, but I can't find it through searching - perhaps because the search terms are too heavily used.

Can anyone help?

Tastatura

9:58 pm on Jul 26, 2006 (gmt 0)

10+ Year Member



I am not an expert in PHP nor JS, just know a bit so take this with grain of salt….
As you know PHP scripting is on server side and JS is on client side, hence a “divide”. I saw some examples where people are using “hidden” forms, however I didn’t like that approach much (nothing specific, just personal preference). What I have on my (still in development) test site, is that I will attempt to write a cookie using JS, and then read it back using PHP. Drawback is that from landing page user has to click on one of your internal links, in order for this to work, i.e landing page sets the cookie using JS, and PHP reads it on the second page. Actually this is a drawback with “form” approach as well. Additional drawback with “cookie” approach is if user has cookies disabled, meaning that you can’t determine with certainty if user has JS enabled or not.

HTH,
Tastatura

dreamcatcher

10:17 pm on Jul 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Will,

Can you not just use the <noscript> tags?

<noscript>Your browser does not support JavaScript!</noscript>

dc

opifex

10:35 pm on Jul 26, 2006 (gmt 0)

10+ Year Member



if the banner is a static image, put it as the background in a table or layer measuring 100% with the image width at 1020 px. no problem putting active content in a layer (ie DHTML). I java is OFF ... and this almost never is the case within the general public .... a visual something will be displayed.

Will Hamilton

12:57 am on Jul 29, 2006 (gmt 0)

10+ Year Member



dreamcatcher,
You're right, <noscript> will work just fine in this case. I thought too hard about it and from a php-POV instead of a java-POV.

Now, of course, IE is throwing a hissy fit. It's leaving a thin gap between the two tables I have. There's one table containing the banner image, and another below it containing the sidebar image; they fit together to form one seamless image. Usually.

<TABLE border="0" cellspacing="0" cellpadding="0">
<TR>
<TD>
<SCRIPT LANGUAGE="javascript">document.write(banner);</SCRIPT>
<NOSCRIPT>Test</NOSCRIPT>
</TD>
</TR>
</TABLE>

The only difference I've made is adding the NOSCRIPT code and now IE is leaving that bloody gap, bah. It leaves it when viewing it with Java on, I don't see why it's reading the noscript at all in that case.

DanA

8:01 am on Jul 29, 2006 (gmt 0)

10+ Year Member



IE reserves some space for the text.
With an image in your banner you could apply vertical-align:bottom; or display:block; to the image or use
td img{display:block;}

[edited by: DanA at 8:06 am (utc) on July 29, 2006]

AjiNIMC

2:27 pm on Jul 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



using noscript is the best way to tackle it.

Will Hamilton

1:26 am on Jul 30, 2006 (gmt 0)

10+ Year Member



Thanks Dan; depressing news. I'll have a fiddle with the CSS, all because IE can't cope with a simple thing.