TeddyKiller Posted August 22, 2010 Share Posted August 22, 2010 I've heard the easiest method to displaying something if the users JavaScript is not on, is using no script tags. I want to display something to show the users JavaScript is off, rather than displaying the page. What can be done? I have used styles, so display: none; for the container of the site.. this worked but problem with this is you can view the source in the source code, it is likely you could edit the css and be able to gain access to the site. This is what I want to avoid. So, I could use the "exit;" command in PHP, although this exits even when JavaScript is enabled... so what it is doing, is running the php that's inside the no script tags anyway. So what I want to do, is display a message "Your JavaScript is turned off" and make sure that nothing else gets displayed and main site isn't in the source code. Can it be done? --- Sorry about it being in the wrong place, it's just.. well I was attempting to use PHP, so I thought it'd be php. Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted August 22, 2010 Author Share Posted August 22, 2010 I used a noscript html redirect to go to nojs.html Can anyone explain why this won't work. What should happen is, if javascript is enabled, it'll run whats in the script tags, hide the lblWarning and show lblMistake but this doesn't work. It just keeps lblWarning on display at all times. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" id="horble"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-language" content="en" /> <meta name="description" content="Horble is a social networking community targetted for people of all ages. Horble allows you to make a profile, look for your friends, and meet loads of fantastic new people! It'll target a more wider range of people than the common social networks. So get joining!" > <title>Horble Social Network - Javascript is not enabled!</title> <link rel="shortcut icon" href="assets/images/favicon.ico"> <link rel="icon" href="assets/images/favicon.ico"> <style> body { background:#cccccc; font-family:verdana,arial,sans-serif; font-size:12px; margin:0; padding:0; color:#000000; margin:0; padding:0; text-align:left; direction:ltr; unicode-bidi:embed;} #lblMistake { display:none; } a, a visted, a active { color:#e11919; font-weight:bold; text-decoration:none; } a:hover { color:#e11919; font-weight:bold; text-decoration:underline; } </style> <script type="text/javascript"> function valid() { document.getElementById('lblWarning').style.display = "none"; document.getElementById('lblMistake').style.display = "block"; } valid(); </script> </head> <body> <div style="text-align:center; padding:40px;"> <div id="lblWarning"> <strong>Javascript must be enabled to be able to run this site.</strong> <br /><br /> <h3>Microsoft Internet Explorer 6.0+</h3><div><ol><li>Click the <strong>Tools</strong> menu.</li><li>Select <strong>Internet Options</strong>.</li><li>Click the <strong>Security</strong> tab.</li><li>Click the <strong>Custom Level</strong> button.</li><li>Scroll down until you see the 'Scripting' section. Select the 'Enable' radio button for 'Active Scripting.'</li><li>Click the <strong>OK</strong> button.</li><li>If you see a confirmation window, click the <strong>Yes </strong>button. </li></ol></div> <h3>Mozilla Firefox 3.6+</h3><div><ol><li>Click the <strong>Tools</strong> menu.</li><li>Select <strong>Options</strong>.</li><li>Click the <strong>Content</strong> tab.</li><li>Select the 'Enable JavaScript' checkbox.</li><li>Click the <strong>OK</strong> button.</li></ol></div> <h3>Safari 2 or 3</h3><div><ol><li>Click the <strong>Safari</strong> menu.</li><li>Select <strong>Preferences</strong>.</li><li>Click the <strong>Security</strong> tab.</li><li>Select the 'Enable JavaScript' checkbox.</li></ol></div> <br /><a href="nojs.html">Reload</a> </div> <div id="lblMistake"> <strong>Your javascript is enabled, you must be here by mistake!</strong> <br /> Go back to <a href="http://www.horble.com">Horble</a> </div> </div> </body> </html> whats wrong? thanks. Quote Link to comment Share on other sites More sharing options...
KevinM1 Posted August 23, 2010 Share Posted August 23, 2010 Most likely a runtime issue. JavaScript will attempt to obtain references to elements before they exist, which will in turn break your script. Use either window.onload = function(){ // script code here } Or put your script at the bottom of the page to ensure the elements are rendered before JavaScript attempts to use them. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.