KevinM1 Posted August 30, 2011 Share Posted August 30, 2011 @rosslad2011, mjdamato was right on in his assessment of your design. Your back end code should be complete without having to rely on JavaScript to do something. JavaScript should be used as a skin on top of your system to add user interaction elements. How you really should be approaching it, if you absolutely need to include/not include something based on JavaScript availability, is to handle the non-JavaScript state as the default, then handle the JavaScript exists state as the part to code around, which is exactly the opposite direction you're currently going in. All that said, your question raises red flags about your overall design. It's hard to say for sure without seeing code, but my inkling is that you're doing it wrong. Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 30, 2011 Share Posted August 30, 2011 I am trying to make my site seamless for those who may have javascript disabled Then you should have stated that from the beginning. I did..... No, you stated you want to include/exclude PHP code on the server based upon whether JavaScript was enabled. But, when you say you want your site to be seamless for users with/without JavaScript then you are talking about "Unobtrusive JavaScript", which is a concept that has been around for years and does not include making server-side changes to support I have a php page and I am trying to get a couple of lines to only be run if Javascript is disabled on the visitors browsers. And I don't see how this is a needless exercise? The rest of your post was not very helpful at all. It is obviously not as straight-forward as you say and your example has nothing to do with what I am trying to do at all. I didn't mean that it is a needless exercise in that the goal you are trying to accomplish is needless or not worthwhile, only that the method you are trying to utilize to meet that goal is the wrong method. So, any further discussions in trying to make that method work are needless. As I stated above, the concept of "unobtrusive JavaScript" (utilizing JavaScript that does not break the user experience for users with JS enabled) has been around for years. In addition, to solving the JS disabled issue, "unobtrusive JavaScript" also addresses inconsistencies on how JS is interpreted between different browsers as well as backward comparability for functions not supported in older browsers. But, one of the core concepts of this process is a separation of the "behavior" layer (i.e. the JavaScript) and the presentation layer (the HTML). The example I gave was just an off-the-cuff example of one very specific scenario. But, the same principles can be applied for any number of scenarios. There are a ton of resources regarding unobtrusive JavaScript that you could take a look at to obtain the goal you are after. Or, you can just disregard everything we have provided and do it your own way. 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.