473,509 Members | 2,828 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I check if javascript is enabled in PHP?

Jim
How do I check if javascript is enabled in PHP?

TIA,

Jim
Sep 27 '06 #1
6 61588

"Jim" <Ji******@fwewef.csowrote in message
news:Cv******************@fe1.news.blueyonder.co.u k...
How do I check if javascript is enabled in PHP?

TIA,

Jim

http://www.google.com/search?q=check...&btnG=Search&h
l=en&ie=ISO-8859-1
Sep 27 '06 #2
you use a function called get_browser()
it takes no parameters and anaylzes the HTTP_USER_AGENT
it return an assoctive array
you check "javascript" key and if it is set to 1 then javascript is
enabled
For example:
$results = get_browser();
if ($results["javascript"] == 1) {
echo "You have javascript";
}

One thing you need to now is you must set the browscap.ini in your
php.ini file to the location of you browscap.ini. You can get one at
http://browsers.garykeith.com/downloads.asp

Happy detection
Jim wrote:
How do I check if javascript is enabled in PHP?

TIA,

Jim
Sep 28 '06 #3
Benjamin schreef:
you use a function called get_browser()
it takes no parameters and anaylzes the HTTP_USER_AGENT
it return an assoctive array
you check "javascript" key and if it is set to 1 then javascript is
enabled
Err: It only indicates if the browser supports javascript, not if it's
enabled or not.
JW
Sep 28 '06 #4

Benjamin wrote:
you use a function called get_browser()
it takes no parameters and anaylzes the HTTP_USER_AGENT
it return an assoctive array
you check "javascript" key and if it is set to 1 then javascript is
enabled
For example:
$results = get_browser();
if ($results["javascript"] == 1) {
echo "You have javascript";
}

One thing you need to now is you must set the browscap.ini in your
php.ini file to the location of you browscap.ini. You can get one at
http://browsers.garykeith.com/downloads.asp

Happy detection
Jim wrote:
How do I check if javascript is enabled in PHP?

TIA,

Jim
Of course that will only tell you if the browser /supports/ JavaScript
-- not whether it is actually enabled or not.

Your best bet is probably to use JavaScript to do something like set a
form variable then check if that variable got set when you process the
form.

Sep 28 '06 #5
NC
Jim wrote:
>
How do I check if javascript is enabled in PHP?
The temptation is to use get_browser() function, but it must be
resisted. get_browser() provides you with information about
what the browser CAN do. It cannot, however, tell you whether
the browser IS ALLOWED to do all it can. For example, many
browsers are capable of supporting JavaScript, but in many,
its support can be disabled.

So it's tricky. You can't do "it in one sitting"; you need to
output something (including some JavaScript), then see how the
client reacts to it. For example, this could be your index.php:

<html>
<head>
<script language="JavaScript">
window.location =
'http://www.yoursite.com/index1.php?js=1&token=<?php
echo time();
?>';
</script>
</head>
<body>
<p>Sorry, your browser does not support JavaScript...</p>
</body>
</html>

In index1.php, you check if $_GET['js'] is indeed 1 and if
$_GET['token'] is reasonably close to server's current time.

You will also need a mechanism to propagate this piece of
information...

Cheers,
NC

Sep 28 '06 #6
Jim wrote:
How do I check if javascript is enabled in PHP?

TIA,

Jim


Tim,

Just my two pennies:

Don't use PHP to check for javascript enabled / disabled.

Make your pages function properly without javascript, i.e. don't have
any inline javascript in your page - nothing essential should be done
using javascript.

Then in the pages link in an external javascript file in the header.
In this javascript file use something along the lines of:

window.onload = init;

function init() {
// add any javascript functions to the page using the DOM
}
This way, your users can use your site independently of whether
javascript is enabled or disabled as the javascript is only 'added' if
the user has javascript enabled.

An elegant and user-friendly way to deal with the problem.

Good luck,
Juliette

P.S.: if none of the above makes sense to you, stay away from javascript
in the first place.
Sep 29 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7374
by: Randell D. | last post by:
Folks, I've heard of buffer overflows being used/abused by hackers and believe one method to reduce this from happening is to check the length of my form data before writing it to my MySQL...
13
8441
by: Alex Molochnikov | last post by:
Is there any way to find out programmatically if Javascript is supported/enabled in a browser? By "programmatically" I mean on the Java servlet side. TIA Alex Molochnikov Gestalt Corporation
7
8362
by: Diego | last post by:
Hi My question is if exists any way to check if javascript is disabled on the client browser, I have tried with browser.javascript but this only return to me if the browser has the capability,...
2
6461
by: Mike Moore | last post by:
Is there an easy way to check if Java Script is enabled in the MS Internet Explorer browser for versions 5.0 and above? Also, how might I test this?
10
1910
by: David Thielen | last post by:
Hi; When a user clicks a radio button, what I would like to do is that if javascript is enabled on their browser, it calls a javascript function and does not do a postback. If javascript is...
8
2835
by: Taras_96 | last post by:
Hi everyone, We' ve come to the conclusion that we wish the user to be directed to an error page if javascript is disabled <enter comment about how a webpage shouldn't rely on javascript here :)...
6
3308
by: Anshul | last post by:
I want to check through perl whether javascript is enabled or disabled in mozilla browser. If it is disabled I want to display a message to user to enable it. What code can I use please help. I...
12
2775
by: Anic297 | last post by:
Hi, This is certainly a simple question, but I'm a newbie in JavaScript. Is there a way to know if JavaScript is enabled? My php script uses JavasSript to do something. If JavaScript is not...
3
7772
by: =?Utf-8?B?Qkw=?= | last post by:
if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1571
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.