Shouldn't we use

前端 未结 11 942
北荒
北荒 2020-12-07 09:08

I found some good cons here:

  • The noscript element only detects whether the browser has JavaScript enabled or not. If JavaScript is disabled in the Firewall

11条回答
  •  遥遥无期
    2020-12-07 09:35

    After pondering for many days and changing my code back and forth, I think I have clearer picture now and would like to share my two cents worth on the subject before I forget.

    show non-js content

    vs

    
    
    

    Depending on the situation, there are three cases for consideration:

    Case 1 - If required script is inline

    JavaScript disabled

    • Content in
    • Content in
      element appears immediately, non-js content is shown

    JavaScript enabled

    • Content in
    • Content in
      element may momentarily appear before being hidden, js content shown

    For this case, using

    Case 2 - If required script is from external (third-party) source, but hiding of
    element is done with inline script

    JavaScript disabled

    • Content in
    • Content in
      element appears immediately, non-js content is shown

    JavaScript enabled but required script is blocked

    • Content in
    • Content in
      element may momentarily appear before being hidden, nothing is shown!

    JavaScript enabled and required script is received

    • Content in
    • Content in
      element may momentarily appear before being hidden, js content shown

    For this case, using

    Case 3 - If required script hides the
    element

    JavaScript disabled

    • Content in
    • Content in
      element appears immediately, non-js content is shown

    JavaScript enabled but required script is blocked

    • Content in
    • Content in
      element appears, non-js content is shown

    JavaScript enabled and required script is received

    • Content in
    • Content in
      element may momentarily appear before being hidden, js content shown

    For this case, using

    element is advantageous.

    In summary

    Use

    element and make sure that the required script contains:

    document.getElementById('noscript').style.display='none';
    

提交回复
热议问题