...

View Full Version : can i detect if JS is disabled?



canadianjameson
09-09-2004, 09:03 PM
i realise that reading the "disabled/enabled" value from the users settings would be a security risk... so heres an idea

can a script be used to send a JS command (or something) to a user, and if the command isnt rejected then that means JS is enabled?

fci
09-09-2004, 10:05 PM
<NOSCRIPT>
<P>Access the <A href="http://someplace.com/data">data.</A>
</NOSCRIPT>

http://www.w3.org/TR/REC-html40/interact/scripts.html#h-18.3.1

canadianjameson
09-09-2004, 11:38 PM
i suppose that works

Kor
09-10-2004, 08:47 AM
or, if you need it for another event handler inside the page

<a href="nonjspage.html" onclick="location.href='jspage.html';return false">GO</a>

canadianjameson
09-23-2004, 10:32 PM
actually i meant something more involved than that.. come to think of it.

i wanted to know if i could do something like this

mad suedo code:



<script>
... try to activate a simple js function.

function jsYesNo ()
{
var test = 0;
test = test + 1;

if (test = 1)
{ return true; }
else
{ return false; }
}


<body>

<div if jsYesNo="false" (show this div)>
Javascript is needed for this page blahblah
</div>


i figured i could use something non-js to evaluate whether a JS function worked. if it didnt i could program the reaction accordingly

Garadon
09-23-2004, 10:50 PM
anything in noscript tags is only shown if no script is enabled. And btw logic dictate that you cannot use something thats disabled to test if its disabled, simply for the simple reason that it wouldn't truely be disabled then.

<noscript>
<div if jsYesNo="false" (show this div)>
Javascript is needed for this page blahblah
</div>
</noscript>

canadianjameson
09-24-2004, 04:46 AM
does noscript only apply to javascript, or all types of scripting?

glenngv
09-24-2004, 06:09 AM
For IE, it also covers client-side VBScript.

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

jbot
09-24-2004, 09:30 AM
in IE you can't solely disabled JS but leave VBS enabled. this is because both scripting techs are subsumed under ActiveScripting. in order to disable one or the other, you disable ActiveScripting and therefore both.

this presumably also pertains to any other scripting that may be possible clientside such as Ruby, PerlScript, etc (tho I've never known it possible to script the client with these, so i ... er ... guess not then LOL).

dumpfi
09-24-2004, 06:13 PM
If you want to show/hide some content of a page if javascript is disabled, let js append/remove the content or have the element be hidden/shown by default and change it with js, e.g.:



<script type='text/javascript'>
function show_content() {
document.getElementById('no_js').style.display = 'none';
}
window.onload = show_content;
</script>

...

<div id='no_js'>javascript needed.</div>
dumpfi

canadianjameson
09-25-2004, 01:56 AM
sounds good, however i would need it to appear IF javascript was disabled

which puts us back at the noscript option :)

does noscript take up space on the page??

i.e the difference between visibility.hide and display: none being one still keeps it in the page spacewise and one doesnt...

dumpfi
09-25-2004, 11:53 AM
sounds good, however i would need it to appear IF javascript was disabled

which puts us back at the noscript option :)
I think you haven't understood what i said. If you have an element in your page and use js to hide it, the element will still be visible if js is disabled.

dumpfi

canadianjameson
09-25-2004, 03:09 PM
I think you haven't understood what i said. If you have an element in your page and use js to hide it, the element will still be visible if js is disabled.

dumpfi

heh, i think you have misunderstood my intentions kind sir.

i'm not using JS to hide anything, i wanted to show a message to users whose JS was disabled, but not to people whose wasnt. i was look for a way to test whether a user had it disabled, and based on that being true, show something. however i've realised this is logically impossible to do without an IF statement... putting us back to square one

andyede
09-25-2004, 03:13 PM
Isn't that exactly what the <NOSCRIPT> tag is for?

dumpfi
09-25-2004, 04:20 PM
heh, i think you have misunderstood my intentions kind sir.

i'm not using JS to hide anything, i wanted to show a message to users whose JS was disabled, but not to people whose wasnt.I don't think there would be a difference for normal users if the message was hidden or nonexistent if they had js enabled. In both cases the user doesn't notice it.

But go with the noscript-tag if you like it.

dumpfi

canadianjameson
09-25-2004, 06:23 PM
cool, thx



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum