473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

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 61580

"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
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
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
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
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
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
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
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
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
by: =?Utf-8?B?Qkw=?= | last post by:
if (Request.Browser.Cookies) { // Cookies supported } else { // Web browser not supports cookies }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.