PHP &

后端 未结 10 1802
误落风尘
误落风尘 2021-01-20 13:40

Is this correct? If not what is the correct syntax

I am new to php hence trying to learn.

    

        
10条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-20 14:00

    You can use the noscript tags to display content to browsers with javascript disabled or redirect them to another page (a nojs-version.php for example).

    
        
    
    
    
    

    Modernizr

    The better way to handle javascript detection (& feature) would be to use Modernizr: http://modernizr.com

    Check out this SO question: What is the purpose of the HTML "no-js" class?

    A basic example (without Modernizr)

    You could add the class no-js on page load to your tag. Then when the page loads and if javascript is enabled, you can replace the no-js with js like so:

    // When the DOM is ready & loaded, do this..
    $(document).ready(function(){
        // Remove the `no-js` and add the `js` (because JS is enabled (we're using it!)
        $('body').removeClass('no-js').addClass('js');
    
        // Assign it to a var so you don't traverse the DOM unnecessarily.
        var useJS = $('body').hasClass('js');
        if(useJS){
            // JS Enabled
        }
    });
    

    The above code is a very basic example of how modernizr works. I would highly recommend just using that.

    Check out Modernizr

提交回复
热议问题