Comment On Bulletproof JavaScript Detection

"I work at a major financial services company," writes Seth. "We have a public site that requires JavaScript be enabled. When it's not, the visitor is redirected to an error page that explains the website's requirements." [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Bulletproof JavaScript Detection

2009-03-16 09:06 • by Cri (unregistered)
if(!isFirstComment()){
location.href="wtf.htm";
}

Re: Bulletproof JavaScript Detection

2009-03-16 09:08 • by DOA
That must be the very definition of facepalm code.

Re: Bulletproof JavaScript Detection

2009-03-16 09:11 • by aggle-rithm
if(!user_owns_a_computer()) return false;
return true;

Re: Bulletproof JavaScript Detection

2009-03-16 09:14 • by Jon (unregistered)
Wow, I don't normally comment, but that made me say "W T F" (as separate letters!) out loud...

Re: Bulletproof JavaScript Detection

2009-03-16 09:17 • by aggle-rithm
249619 in reply to 249616
aggle-rithm:
if(!user_owns_a_computer()) return false;
return true;


Oops, I just realized this is badly flawed code. Should be:

return using_a_computer();

Implementation:

function using_a_computer()
{
switch(get_hardware_type())
{
case(COMPUTER) return true;
case(MICROWAVE) return false;
case(ANSWERING_MACHINE) return false;
case(BATTERY_OPERATED_MARITAL_AID) return false;
}
}

No, I'm not giving you the implementation for get_hardware_type(). Do I have to do everything?

Re: Bulletproof JavaScript Detection

2009-03-16 09:20 • by Not THAT Alex (unregistered)
Schodinger-Oriented Programming

(CAPTCHA:appellatio. Who is going to protect us?)

Re: Bulletproof JavaScript Detection

2009-03-16 09:26 • by Shipment of Fail (unregistered)
I suppose this is the Web 2.0 reinvention of <noscript>.

Re: Bulletproof JavaScript Detection

2009-03-16 09:29 • by Friendly Neighborhood QA (unregistered)
249623 in reply to 249619
aggle-rithm:
aggle-rithm:
if(!user_owns_a_computer()) return false;
return true;


Oops, I just realized this is badly flawed code. Should be:

return using_a_computer();

Implementation:

function using_a_computer()
{
switch(get_hardware_type())
{
case(COMPUTER) return true;
case(MICROWAVE) return false;
case(ANSWERING_MACHINE) return false;
case(BATTERY_OPERATED_MARITAL_AID) return false;
}
}

No, I'm not giving you the implementation for get_hardware_type(). Do I have to do everything?


Your code submission lacks (A) the critical "FOR CASE" construct
(B) the following "computer equipment" type case:

case(WOODEN_TABLE) return FILE_NOT_FOUND;


Please correct deficiencies and re-submit for code re-audit per Consolidated Process Work Instructions SWE-15893-122, QE-5613-123, and VTE-1348-992 within 5 working days to avoid implementation scheduling variance.

Re: Bulletproof JavaScript Detection

2009-03-16 09:35 • by Another Andrew (unregistered)
function validateSettings(){
if(!javascriptEnabled()){
// << Armageddon here if user enables javascript just in time
location.href="no_js.htm";
}
}

Re: Bulletproof JavaScript Detection

2009-03-16 09:36 • by mxx
This somehow reminds me of Quietust's signature (no, not signature guy, the one about the note).

10 Reasons why your coding-slaves sucks

2009-03-16 09:37 • by Tempura (unregistered)
1) They appear on thedailywtf.com

10) They appear on thedailywtf.com, because they made a wtf failure.

Re: Bulletproof JavaScript Detection

2009-03-16 09:39 • by Quietust
249628 in reply to 249626
mxx:
This somehow reminds me of Quietust's signature (no, not signature guy, the one about the note).


For the benefit of others, that would be "P.S. If you don't get this note, let me know and I'll write you another." (which is a quote from a The Three Stooges short).

Re: Bulletproof JavaScript Detection

2009-03-16 09:48 • by Osno (unregistered)
Original dev: "Well, it works on my computer!"

Re: Bulletproof JavaScript Detection

2009-03-16 09:50 • by kalleguld (unregistered)
Javascript, motherf*cker! Do you speak it?

There really is only one answer

Re: Bulletproof JavaScript Detection

2009-03-16 09:55 • by ih8u (unregistered)
249634 in reply to 249614
DOA:
That must be the very definition of facepalm code.


It reminds me of a time when email went down at a reasonably large company I used to work for. We were told to log off our email clients and wait until further notice to log back in -- or we'd wreck the system and end life on earth.

Much later in the day, we received word from the boss that it was ok to check email again and found a message from the admins that said something like "email works now. you can log back in. kthx".

Re: Bulletproof JavaScript Detection

2009-03-16 09:59 • by Henk (unregistered)
Omg... ontzettende prutsers.

Re: Bulletproof JavaScript Detection

2009-03-16 10:01 • by mauhiz (unregistered)
What's the most disturbing, that junior dev was never checked on, or that senior dev codes like that?

Re: Bulletproof JavaScript Detection

2009-03-16 10:03 • by Brompot (unregistered)
249638 in reply to 249634
ih8u:
DOA:
That must be the very definition of facepalm code.


It reminds me of a time when email went down at a reasonably large company I used to work for. We were told to log off our email clients and wait until further notice to log back in -- or we'd wreck the system and end life on earth.

Much later in the day, we received word from the boss that it was ok to check email again and found a message from the admins that said something like "email works now. you can log back in. kthx".


Here we send and email, alert the receiver by SMS, ICQ them to check their phone and walk by to tell them they're wanted on ICQ. Just in case some medium fails.

Re: Bulletproof JavaScript Detection

2009-03-16 10:06 • by jlintz (unregistered)
So this is why the stock market crashed

Re: Bulletproof JavaScript Detection

2009-03-16 10:08 • by Devilfish (unregistered)
I can't decide whether I should comment on this WTF or knock myself unconscious over it.

So, if you don't see this comment, I've chosen the latter, so please call an ambulance.

Re: Bulletproof JavaScript Detection

2009-03-16 10:11 • by BeOS easter eggs (unregistered)
http://www.eeggs.com/items/15121.html




#include <stdio.h>
#include <be/kernel/OS.h>

int main()
{
printf("%f\n", is_computer_on());
printf("%i\n", is_computer_on_fire());
}

Re: Bulletproof JavaScript Detection

2009-03-16 10:13 • by aggle-rithm
249642 in reply to 249623
Friendly Neighborhood QA:


Your code submission lacks (A) the critical "FOR CASE" construct
(B) the following "computer equipment" type case:

case(WOODEN_TABLE) return FILE_NOT_FOUND;


Please correct deficiencies and re-submit for code re-audit per Consolidated Process Work Instructions SWE-15893-122, QE-5613-123, and VTE-1348-992 within 5 working days to avoid implementation scheduling variance.


Your rejection of my code has been rejected.

If you would like to appeal this rejection, please fill out form 1080SWBS9 and file it under "Q" in the file cabinet of your choice.

Thank you.

Re: Bulletproof JavaScript Detection

2009-03-16 10:15 • by aggle-rithm
249643 in reply to 249641
BeOS easter eggs:
http://www.eeggs.com/items/15121.html




#include <stdio.h>
#include <be/kernel/OS.h>

int main()
{
printf("%f\n", is_computer_on());
printf("%i\n", is_computer_on_fire());
}




This is exactly the sort of code I dream about at night.

Night after night.

Sometimes, I wish I could have my old brain back...

Re: Bulletproof JavaScript Detection

2009-03-16 10:18 • by DOA
249644 in reply to 249633
kalleguld:
Javascript, motherf*cker! Do you speak it?
Quoted for awesomeness.

Re: Bulletproof JavaScript Detection

2009-03-16 10:18 • by DeLos
so what is a good way to check for JS detection...

Re: Bulletproof JavaScript Detection

2009-03-16 10:26 • by Edward Royce (unregistered)
Hmmm.

I don't see what the problem is.

If Javascript is not enabled then the function won't operate. Thus success!

Sooooo. What's yer problem then?

*LAUGH*

Re: Bulletproof JavaScript Detection

2009-03-16 10:27 • by evilspoons
*headdesk*

Re: Bulletproof JavaScript Detection

2009-03-16 10:28 • by Pez (unregistered)
Erm... Don't do it. Graceful degradation / progressive enhancement FTW

Re: Bulletproof JavaScript Detection

2009-03-16 10:28 • by Anonymous (unregistered)
249651 in reply to 249645
The simplest way is to present the non-javascript version and turn on javascript functionality using javascript. If the javascript page is very different you may redirect the user with javascript.

The best way is to make sure that the page works without javascript so you don't really care if the user has javascript enabled or not.

Re: Bulletproof JavaScript Detection

2009-03-16 10:29 • by JuanCarlosII (unregistered)
249652 in reply to 249645
<noscript>
<script type="text/javascript">
location.href = 'no_js.htm';
</script>
</noscript>

... obviously.

Re: Bulletproof JavaScript Detection

2009-03-16 10:32 • by FriedDan
Heh, well, it didn't make it past me into general testing, but I had something similar here.

The developers were using JavaScript to hide the "You must enable Javascript" message, but the users were complaining that the message would sometimes flash on screen as the page loaded.

So what did the developers do? Flip the logic of course (to use Javascript to make the message appear if Javascript was turned off).

More disturbing (yes, it gets worse) is that I suggested using <noscript> BEFORE they made the change, and again afterwards... but it took 2 more tries for them to actually listen. All of which was, of course, after I had to convince my boss that the <noscript> tag wasn't some kind of personal hack that was just an excuse for an ego trip for me.

Disclaimer: I wrote none of this code, nor was I around when it was written. Nor will I be around for more fun and games after I leave for greener (and saner) pastures on Friday.

Re: Bulletproof JavaScript Detection

2009-03-16 10:46 • by Leo (unregistered)
249655 in reply to 249638
Brompot:

Here we send and email, alert the receiver by SMS, ICQ them to check their phone and walk by to tell them they're wanted on ICQ. Just in case some medium fails.


ICQ? Is it still 1999 where you work?

Re: Bulletproof JavaScript Detection

2009-03-16 10:48 • by Edward Royce (unregistered)
249656 in reply to 249645
DeLos:
so what is a good way to check for JS detection...


Have the default version be the Javascript disabled and then have a <script> tag that redirects the browser to the Javascript enabled version.

<script>
window.location = "http://www.myuglywebsite.com/js_enabled.php";
</script>

If Javascript = off then you're ok.

If Javascript = on then the browser gets redirected.

*shrug* that's what I know. Is there a better method?

Re: Bulletproof JavaScript Detection

2009-03-16 10:51 • by FriedDan
249657 in reply to 249656
Edward Royce:
DeLos:
so what is a good way to check for JS detection...


Have the default version be the Javascript disabled and then have a <script> tag that redirects the browser to the Javascript enabled version.

<script>
window.location = "http://www.myuglywebsite.com/js_enabled.php";
</script>

If Javascript = off then you're ok.

If Javascript = on then the browser gets redirected.

*shrug* that's what I know. Is there a better method?


For those who have missed the references.

The <noscript> tag. Content inside this tag is only shown if JavaScript is turned off or if the browser does not support it.

http://www.w3schools.com/TAGS/tag_noscript.asp

Re: Bulletproof JavaScript Detection

2009-03-16 10:56 • by John (unregistered)
249658 in reply to 249652
JuanCarlosII:
<noscript>
<script type="text/javascript">
location.href = 'no_js.htm';
</script>
</noscript>

... obviously.


Ouch, almost wrote a serious reply to that one. I did try to add a method to unset the content attribute in a meta tag, but it that doesn't work as the browser's already started the timer to refresh/redirect the page (even if I extend the delay).

<meta id='metaRefresh' http-equiv='refresh' content='1;url=http://www.google.com' />
<script type='text/javascript'>//<![CDATA[
document.getElementById('metaRefresh').content = null;
//]]></script>

Removing the tag from the head doesn't work either.

Re: Bulletproof JavaScript Detection

2009-03-16 10:56 • by Sashlik (unregistered)
249659 in reply to 249655
Leo:
Brompot:

Here we send and email, alert the receiver by SMS, ICQ them to check their phone and walk by to tell them they're wanted on ICQ. Just in case some medium fails.


ICQ? Is it still 1999 where you work?


We love ICQ here in Russia, and use it widely :)

Re: Bulletproof JavaScript Detection

2009-03-16 11:03 • by John (unregistered)
249660 in reply to 249657
FriedDan:
Edward Royce:
DeLos:
so what is a good way to check for JS detection...


Have the default version be the Javascript disabled and then have a <script> tag that redirects the browser to the Javascript enabled version.

<script>
window.location = "http://www.myuglywebsite.com/js_enabled.php";
</script>

If Javascript = off then you're ok.

If Javascript = on then the browser gets redirected.

*shrug* that's what I know. Is there a better method?


For those who have missed the references.

The <noscript> tag. Content inside this tag is only shown if JavaScript is turned off or if the browser does not support it.

http://www.w3schools.com/TAGS/tag_noscript.asp


But it's not the way management wanted it. How are you going to explain to your starving children that there's no food as daddy ignored his superiors.

Re: Bulletproof JavaScript Detection

2009-03-16 11:05 • by Beldar the Phantom Replier (unregistered)
249663 in reply to 249658
John:
JuanCarlosII:
<noscript>
<script type="text/javascript">
location.href = 'no_js.htm';
</script>
</noscript>

... obviously.


Ouch, almost wrote a serious reply to that one. I did try to add a method to unset the content attribute in a meta tag, but it that doesn't work as the browser's already started the timer to refresh/redirect the page (even if I extend the delay).

<meta id='metaRefresh' http-equiv='refresh' content='1;url=http://www.google.com' />
<script type='text/javascript'>//<![CDATA[
document.getElementById('metaRefresh').content = null;
//]]></script>

Removing the tag from the head doesn't work either.

I guess someone has been missing out on classic articles.

Re: Bulletproof JavaScript Detection

2009-03-16 11:08 • by RBoy (unregistered)
249664 in reply to 249659
Sashlik:
Leo:
Brompot:

Here we send and email, alert the receiver by SMS, ICQ them to check their phone and walk by to tell them they're wanted on ICQ. Just in case some medium fails.


ICQ? Is it still 1999 where you work?


We love ICQ here in Russia, and use it widely :)


In Soviet Russia, you don't seek me, ICQ!


I'll be here all week, try the veal.

Re: Bulletproof JavaScript Detection

2009-03-16 11:12 • by FriedDan
249665 in reply to 249660
John:
FriedDan:

For those who have missed the references.

The <noscript> tag. Content inside this tag is only shown if JavaScript is turned off or if the browser does not support it.

http://www.w3schools.com/TAGS/tag_noscript.asp


But it's not the way management wanted it. How are you going to explain to your starving children that there's no food as daddy ignored his superiors.


I dunno, even my "superior" caved after the developers screwed it up a few times.

And then there's the added bonus of telling the "superior" that he has to explain to his boss about that pesky 2 weeks notice that helps a lot.

Re: Bulletproof JavaScript Detection

2009-03-16 11:19 • by Ketchup (unregistered)
249667 in reply to 249659
Sashlik:
Leo:


ICQ? Is it still 1999 where you work?


We love ICQ here in Russia, and use it widely :)


Nope, here in Russia we hate ICQ, it blocks alternative open-source clients and russian IP.
Now we switching to jabber, including Google Talk.

Re: Bulletproof JavaScript Detection

2009-03-16 11:20 • by John (unregistered)
249668 in reply to 249663
Beldar the Phantom Replier:
John:
JuanCarlosII:
<noscript>
<script type="text/javascript">
location.href = 'no_js.htm';
</script>
</noscript>

... obviously.


Ouch, almost wrote a serious reply to that one. I did try to add a method to unset the content attribute in a meta tag, but it that doesn't work as the browser's already started the timer to refresh/redirect the page (even if I extend the delay).

<meta id='metaRefresh' http-equiv='refresh' content='1;url=http://www.google.com' />
<script type='text/javascript'>//<![CDATA[
document.getElementById('metaRefresh').content = null;
//]]></script>

Removing the tag from the head doesn't work either.

I guess someone has been missing out on classic articles.


Hmm, I'd forgotten about that one. If that's a reference to my solution being overcomplicated, I disagree. It was the first solution I came up with that allowed the page to be redirected when Javascript is disabled.

Other methods are:
Redirecting to a page when javascript is enabled: not ideal because the majority of users enable javacript (as long as we're talking about a non-techie website).

Using javascript to overwrite an element describing why javascript is needed can cause an annoying flicker when the page is loading, so again not ideal.

That said, most my pages use javascript, but will still work if javascript is disabled as the effects are replicated by a post or get. Bit tedious but does mean the site is fast for javascript lovers and works for javascript haters.

Re: Bulletproof JavaScript Detection

2009-03-16 11:23 • by OneMHz
This WTF wins the intertubes.

Re: Bulletproof JavaScript Detection

2009-03-16 11:25 • by Code Dependent
249670 in reply to 249619
aggle-rithm:
case(BATTERY_OPERATED_MARITAL_AID) return false;
Wouldn't that more accurately be, BATTERY_OPERATED_BACHELORETTE_AID?

Re: Bulletproof JavaScript Detection

2009-03-16 11:30 • by Anon (unregistered)
249671 in reply to 249670
Code Dependent:
aggle-rithm:
case(BATTERY_OPERATED_MARITAL_AID) return false;
Wouldn't that more accurately be, BATTERY_OPERATED_BACHELORETTE_AID?


Someone's never been married for 5+ years...

Re: Bulletproof JavaScript Detection

2009-03-16 11:43 • by justsomedude (unregistered)
Gems like this make it easy for me to brush off the stigmas surronding VB. When it comes to code quality, which language is used seems significantly less important than the skill of the developers using them ;-)

Re: Bulletproof JavaScript Detection

2009-03-16 11:44 • by mort8104 (unregistered)
<%
/**
* a bulletproof test for the presence of a running computer
* NOTE: also requires a browser, a connection to the Apache instance, and a user.
**/
function UsingComputer()
{
return true;
}

switch (UsingComputer)
{
case true:
echo 'congratulations, you appear to be using a computer';
break;
default:
echo 'oh dear, for this code to run you need a computer';
break;
}
%>

Re: Bulletproof JavaScript Detection

2009-03-16 11:47 • by Edward Royce (unregistered)
Well.

"Redirecting to a page when javascript is enabled: not ideal because the majority of users enable javacript (as long as we're talking about a non-techie website). "

Sure it's not ideal. What would be ideal is if the browser reported to the server in a variable the state of Javascript on/off and perhaps a type or version number or some such thing.

Frankly the whole issue of Javascript on/off, issues with differences in functions, objects, DOM and other bullcrap makes writing web apps annoying at best and vastly irritating at worst.

No wonder so many people are doing sites in flash.

Re: Bulletproof JavaScript Detection

2009-03-16 11:49 • by Edward Royce (unregistered)
249676 in reply to 249673
justsomedude:
Gems like this make it easy for me to brush off the stigmas surronding VB. When it comes to code quality, which language is used seems significantly less important than the skill of the developers using them ;-)


Hell if you think this stuff is amusing you see Google the fools who want to use Javascript as their language for doing -server side- coding.

*shrug* what can I say.

Re: Bulletproof JavaScript Detection

2009-03-16 11:50 • by LHC (unregistered)
249677 in reply to 249670
Code Dependent:
aggle-rithm:
case(BATTERY_OPERATED_MARITAL_AID) return false;
Wouldn't that more accurately be, BATTERY_OPERATED_BACHELORETTE_AID?


I thought that was a typo - battery operated nunchakas!!
« PrevPage 1 | Page 2 | Page 3Next »

Add Comment