473,287 Members | 3,295 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,287 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 61564

"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 }
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.