Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detact if javascript is enabled without using javascript? :)

Status
Not open for further replies.

jdbolt

Programmer
Joined
Aug 10, 2005
Messages
89
Location
CA
Hi,

I was wondering if there was a way to detect if javascript is enabled and if not, display a message, no matter how simple, just a message somewhere.

I dont want to have a message telling the user javascript is required, just want to tell them it is when its not enabled.

Is this even possible?
 
use the [tt]<noscript></noscript>[/tt] tags.

Code:
<script type="text/javascript">document.write("javascript enabled");</script>
<noscript>no javascript enabled</noscript>

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
Cool, is there a way to hide content is script is enabled?

Code:
<noscript>no javascript enabled</noscript>
<scriptenabled>
rest od document
</scriptenabled>

 
Yes - hide its container programatically using CSS. For example, if the content you want to hide has a container with an ID of "myContainer", this would work:

Code:
document.getElementById('myContainer').style.display = 'none';

or, better still, to remove the content from the page altogether:

Code:
var objToRemove = document.getElementById('myContainer');
objToRemove.parentNode.removeChild(objToRemove);

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I didnt mean hide the <noscript> tag, I meant hide the rest of the page if javascript is not present

Thanks!
 
The only way would be to have the content hidden by default, and then shown if JS is enabled - bt that's really sucky, and I wouldn't advise you do this.

Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top