/ Published in: HTML
This is just a quick sample that shows how to have a button visible on a page only if the person has JavaScript enabled.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<!DOCTYPE html> <html> <head> <style> body { margin: 0px; padding: 0px; background: url(http://static2.grsites.com/archive/textures/misc/misc221.gif); } .alphaBkg { position: fixed; width: 100%; height: 100%; background: #000; margin: 0px; padding: 0px; opacity: .5; -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; filter: alpha(opacity=50); } .modal { position: fixed; width: 250px; height: 40px; background: #cfcfcf; border: 4px solid #fff; left: 50%; margin-left: -125px; top: 50%; margin-top: -20px; text-align: center; } .inputButton { font-size: 12px; width: 200px; height:42px; position: absolute; left: 50%; margin-left: -100px; top: 50%; margin-top: -21px; } </style> </head> <body> <!-- Set the button to be invisible by default. I have done this with CSS --> <input type="button" id="sampleButton" value="Is your JS working?" onclick="alert('Yes! JavaScript Working!');" class="inputButton" style="display: none;" /> <script type="text/javascript"> //This JavaScript fires if JS is enabled, making the button visible. document.getElementById('sampleButton').style.display = "block"; </script> <noscript> <!-- If JavaScript is disabled the content in between the NOSCRIPT tages is displayed. --> <div class="modal"> </div> </noscript> </body>
URL: http://www.egoant.com/tutorials/samples/JSDisabledSample.html