Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
check if javascript is enabled and return a condition
Hello folks,
I’d like to request for a plugin which detects the unavailability of javascript and conditionally returns a customized message or even a piece of html code. Can anyone whip up such a plugin?
Thank you very much for all your efforts.
Regards,
Vasanth
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: check if javascript is enabled and return a condition
Textpattern is serverside and javascript is clientside.
So i think that a plugin that detects javascript cannot be done.
Even if there should be a sure methode, the better way to include Javascript is using Unobtrusive Javascript
Offline
Re: check if javascript is enabled and return a condition
Oh ok. It comes a surprise to me that PHP doesnt have such a function. I had a notion that it was possible as PHP can determine other user settings like OS, Browser, flash plugin availability. Thanks for the tip. I’ll check out Unobtrusive Javascript.
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: check if javascript is enabled and return a condition
I <a href=“http://www.google.co.in/search?hs=A3U&hl=en&client=firefox-a&rls=org.mozilla%3Aen-US%3Aofficial&q=PHP+%22JAVASCRIPT+DETECTION%22+&btnG=Search&meta=”>googled</a> and found out that a lot of other people have tried to find a solution. Looks like <a href=“http://llamasery.com/forums/showthread.php?p=47521”>this works</a>
I’m looking for advice and exploring the possibility of a plugin.
@Bastian: thank you once again for letting me know about Unobtrusive Javascript. It does look very clean. I’m gonna try implementing it in my site.
Last edited by creativesplash (2006-06-16 10:03:51)
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: check if javascript is enabled and return a condition
It works with a page-reload and it requires sessions enabled.
But yes, it could be done in a plugin. If you like to learn how to write a plugin, there is an article in Textbook, which also links to a tutorial that zem wrote a while ago.
Offline
Re: check if javascript is enabled and return a condition
Sencer wrote
It works with a page-reload and it requires sessions enabled.
If sencer says so, it might be that javascript detection can be done this way ;)
But if you only want to know “Javascript enable [yes|no]” a php session solution is much overdone.
If you want to know “Does xys.js work [Yes|no]” it is very much work:
You have to check minimum for:
- Browser’s name (Its not sure, that user_agent delivers to right one)
- Which version
A plugin which provides usefull informations about users javascript is much work!
I would definetively prefere Unobtrusive Javascript:
- Include Javascript to a xhtml page which is complete usable without javascript
- Add an window.onload handle which adds all javascript issues
That method is its own Javascript detector
Because the javascript is added ofter xhtml is loaded, the user has already an working page if javascript = off
And if javascript = on the script can add some additional features to improve handling, add some animations or other effects
Offline
Re: check if javascript is enabled and return a condition
Oh, I was merely referring to the link that creativesplash posted.
Personally I wouldn’t use that, and I agree with you that the Javascript should not be intermingled with html-code anyhow, so that there is usually very little benefit in knowing in PHP-code whether Javascript is enabled. The actual detection only ever happens with Javascript anyhow (even with the above PHP example), so it makes a lot more sense to keep things together.
btw: There’s also http://bennolan.com/behaviour/ which moves any Javascript completely out of the HTML code.
Offline
Re: check if javascript is enabled and return a condition
I agree with you
And i with you:
there is usually very little benefit in knowing in PHP-code whether Javascript is enabled
Offline
Re: check if javascript is enabled and return a condition
Thank you Sencer and Bastian for replying.
@Bastian: I got some great tips from the unobtrusive Javascript club. Thanks for the link again
@Sencer: Behaviour is really awesome too. There’s a kind of separation between form and function which is really good.
Thanks to you guys for updating me. I kinda feel enlightened (not to flatter you ofcourse).
Regards,
Vasanth
“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”
— Albert Einstein
Offline
Re: check if javascript is enabled and return a condition
A list apart covers this issue in its latest number
Offline