Kirby check if js is enabled

Hi,

I need to implement a different layout configuration if the browser has javascript disabled: I want to have a layout pagination only if js is disabled, otherwise the page is going to load everything through lazyloading.

So far using <noscript>code</noscript> has been useful as long as it’s about showing a piece of html printed by php.

In my case though I need to set a php variable only if js is disabled, so I was wondering if there was a way for kirby to check for that? The simplest thing would be to check with kirby if a dom element has a class, but AFAICS the only way to do that is with a regex?

How would you do it?

Use no-js on the html tag as a class, then use a javscript to swap it to js class if js runs.

I normally use head.js to do this since its built in, but im pretty sure modernizer can do the same thing.

Yes, that works indeed!

I was just hoping to be able to swap classes through php, as I am basically reordering two big div container with flex 's order option, and am not sure how the page reflow would be.

Still, I need to add a php variable only for when javascript is disabled, and in this case swapping classes can’t work /:

You would have to drop a cookie if javascript executes, then read that cookie back to fill up your php var.

Theres not really any other way for javascript to communicate with php.

Thanks for the suggestion! I will probably rethink how I want to progressively enhance the site when javascript is not enabled.