Jump to content

Using PHP to detect user javascript settings


SmokingMan
 Share

Recommended Posts

Can you use PHP to check a user's browser settings to see if javascript has been enabled, and then use a re-direct to another page if they have javascript disabled? I've looked over tutorials and on the PHP.net site and can't find any reference to this. :)

Link to comment
Share on other sites

I didn't feel like checking any PHP things but JavaScript can do that itself.This would go on the page that is non-java script:

<script type="text/javascript"><!--//self.location.href = "(other page)";//--></script>

Might not work the way your thinking of. Idk :)

Link to comment
Share on other sites

I have tried using java script:

<script language="javascript" type="text/javascript">        document.onload = function(){        document.getElementById('content').style.display='block';      }      </script>            <noscript>This page requires JavaScript to be enabled. Please enable it in your browsers settings.</noscript>            <div id="content" style="display:none">            ... html            </div>

...but with mixed results, and none that I liked. That's why I thought I'd see if PHP would do the trick for me. I need for people to have javascript enabled for all of the features to work. If they have javascript disabled, I want to re-direct them to a page to tell them they need to enable javascript. But I wasn't sure if PHP had the capability to check the user's browser settings and re=direct depending on the results.

Link to comment
Share on other sites

As you can tell from my postings, I'm new at this. But I thought about this and decided since PHP is server side scripting, all PHP code is executed prior to knowing anything about the browser.Correct me if I'm off.my 2 cents,-Gal

Link to comment
Share on other sites

As you can tell from my postings, I'm new at this. But I thought about this and decided since PHP is server side scripting, all PHP code is executed prior to knowing anything about the browser.Correct me if I'm off.my 2 cents,-Gal
I'm new to PHP also, that's why I asked :)
Link to comment
Share on other sites

PHP doesn't know anything that happens on the client side, except for information that some browsers send upon requesting a page, like the HTTP referer and User Agent.I usually design my Javascript applications so that the page works well even without Javascript.

Link to comment
Share on other sites

its possible, but not on the first page that gets visited right awayjavascript can save cookies, so just let javascript set a cookie, then on the next page with php you can see if theres a cookie, if javascript is disabled, there wont be a cookie

in java script:function createCookie(name,value,days){	if(days){var date=new Date();		date.setTime(date.getTime()+(days*24*60*60*1000));		var expires="; expires="+date.toGMTString();	}	else{var expires="";}	document.cookie=name+"="+value+expires+"; path=/";}createcookie('js_enabled',true,90);in php on the page after that:if(isset($_COOKIE['js_enabled'])){   // javascript is enabled}

Link to comment
Share on other sites

PHP doesn't know anything that happens on the client side, except for information that some browsers send upon requesting a page, like the HTTP referer and User Agent.I usually design my Javascript applications so that the page works well even without Javascript.
The page will work without javascript enabled. They will be able to navigate with no problem. It's just that not everything embedded in the page will work. If PHP won't work, I'll work it out with javascript.Thanks :)
Link to comment
Share on other sites

I usually do something like this:

<div id="js_warn">This page requires Javascript</div><script type="text/javascript">document.getElementById('js_warn').style.display = 'none';</script>

If Javascript is enabled then they won't see that message.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...