axelstudios Posted June 1, 2007 Share Posted June 1, 2007 Hi guys - I'm looking for a way to detect whether or not a browser has JavaScript enabled using php, rather than the client-side <noscript> tag... I intend to have an alert bar show up at the top of my page only if JavaScript is disabled, or if I want to make an announcement (In the latter example, noscript wouldn't work). There's also the possibility of showing both messages at the same time. Any ideas? If something similar to this has already been posted (I didn't find it), please redirect me... Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/ Share on other sites More sharing options...
ShogunWarrior Posted June 2, 2007 Share Posted June 2, 2007 I don't think you can. Only the browser knows if Javascript is on or off, and unless that information is sent in the inital request headers PHP can't get it. AFAIK only the browser agent string is sent which doesn't include that info. Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-266594 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 You can always do some type of initial check on the first page they visit and than send it with a meta redirect to your main script which then stores it as a session. Dunno if it works, but yea. Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-266619 Share on other sites More sharing options...
ToonMariner Posted June 2, 2007 Share Posted June 2, 2007 As others have rightly pointed out - php can't detect if javascript is enabled or not. What you can do though (if you are ok with the banner only showing on any page AFTER the firts page the user visits) use javascript to add a variable to the end of each link OR alter the value of any submit buttons - in the processing script you could look fro these - if they are present then js 'is' on. (I say 'is' as someone could put this in themselves but theyed have to really want to...) Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-266632 Share on other sites More sharing options...
axelstudios Posted June 2, 2007 Author Share Posted June 2, 2007 Do you think it's even worth it to tell users that JavaScript is disabled? I would guess the large majority of people have it enabled, so maybe it's not even worth it to go through the trouble... PS - Thanks for the replies Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-266980 Share on other sites More sharing options...
per1os Posted June 2, 2007 Share Posted June 2, 2007 No, the percentage of users without JS enabled is like only 2% of all internet users. Not worth it at all. Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-266981 Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 just at the top of your pages... put a... <noscript><span style="font-size:24px;color:red;">You need to have javascript on to view this page</span><div style="display:none; visible:hidden;"></noscript> Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-266991 Share on other sites More sharing options...
thnbgr Posted June 2, 2007 Share Posted June 2, 2007 You could set up an output buffering in the beginning, and echo a script like <script type="text/javascript">document.write('a')</script> and check to see if 'a' was outputed. Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-267081 Share on other sites More sharing options...
taith Posted June 2, 2007 Share Posted June 2, 2007 or make a splash screen... and have javascript set a cookie... retrieve it when you go to your index page... if cookie exists, its enabled... else... nope! Quote Link to comment https://forums.phpfreaks.com/topic/53919-php-alternative-to/#findComment-267092 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.