Jump to content

JS detection script not working


SmokingMan

Recommended Posts

I'm trying to use a script to only display page content when the user's browser has javascript enabled. But when testing this on my local machine, with scripts enabled nothing displays, but when scripts are disabled the 'noscript' message appears along with all of the images in the page that are pulled in via linked URL's.Here's the script I'm using:

 <script type="text/javascript">   document.getElementById("content").style.display.="block";</script> <div class="noscript">   <noscript>-- Attention -- This page requires that Javascript be enabled for all 	 features to work correctly.  Please enable Javascript in your browser and then reload the page.   </noscript> </div>

These are the style declarations in the 'head':

 <style> #content{  display:none; }  .noscript{  width:75%;  font-style:italic;  font-family:'Trebuchet MS',Verdana,Tahoma,Arial,'Arial Black',Helvetica,'Century Gothic','Lucida Sans Unicode',Impact,sans-serif;  font-weight:500;  color:#800000;  font-size:large;  text-align:center;  margin:auto; }  </style>

All of the page contents sits between a set of DIV's with the ID 'content'. Any ideas as to why this isn't working correctly? I'm testing this on my local machine using the XAMPP server package so I don't have to keep uploading files to the web server. I use Firefox and toggle the script permissions on and off for the 'localhost'. I'm at a loss. :)

Link to comment
Share on other sites

Is your content division set to display:none; ?

Link to comment
Share on other sites

Whoops I didn't see that :)Oh - for the not displaying with JavaScript enabled problem, you have one dot too many in the JS bit - it should be

document.getElementById("content").style.display = "block";

Are you sure the images are inside the #content division?

Link to comment
Share on other sites

Are you sure the images are inside the #content division?
Yes, everything is within the 'content' division. I'll make the script change to see what happens.Edit-----------------------------------I made the change and now the content displays when it should. But I still can;t get rid of the linked images displaying with scripts disabled. Would the fact that they are in my page via a URL link make a difference? I wouldn't think so since they are in the 'content' DIV and should not even be loaded since the display property is set to 'none'. Any other ideas? :)
Link to comment
Share on other sites

you might also want to add the document.getElementById call inside the onload (or if you use mootools, ondomready) event.You should attempt to make a fully functional version of your site without JS first, and then use JS to make it work better than it would without it. You should not simply rely on javascript.

Link to comment
Share on other sites

You should attempt to make a fully functional version of your site without JS first, and then use JS to make it work better than it would without it. You should not simply rely on javascript.
The site is functional without JS. It's just that the scripts do add a little more to the site. If I can't get rid of the URL linked images, I'll probably just drop the script detection script. It's not a do or die thing. I did have the document.getElementById inside onload in the 'head' section before with the same problems.Like I said, it's not critical. It mostly now just bothers the heck out of me and I can't let it beat me now :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...