Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-06-16 08:57:55

creativesplash
Member
From: Coimbatore, India
Registered: 2005-01-19
Posts: 283
Website

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

#2 2006-06-16 09:37:50

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

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

#3 2006-06-16 09:48:24

creativesplash
Member
From: Coimbatore, India
Registered: 2005-01-19
Posts: 283
Website

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

#4 2006-06-16 09:59:34

creativesplash
Member
From: Coimbatore, India
Registered: 2005-01-19
Posts: 283
Website

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

#5 2006-06-16 10:54:24

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

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

#6 2006-06-16 12:50:10

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

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

#7 2006-06-16 13:13:02

Sencer
Archived Developer
From: cgn, de
Registered: 2004-03-23
Posts: 1,803
Website

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

#8 2006-06-16 13:29:10

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

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

#9 2006-06-16 17:08:44

creativesplash
Member
From: Coimbatore, India
Registered: 2005-01-19
Posts: 283
Website

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

#10 2006-06-20 21:57:23

Bastian
Plugin Author
From: Wuppertal, Germany
Registered: 2005-02-02
Posts: 376
Website

Re: check if javascript is enabled and return a condition

A list apart covers this issue in its latest number

Offline

Board footer

Powered by FluxBB