Jump to content

Piece of PHP only if JS is disabled


rosslad2011

Recommended Posts

@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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.