Skip to content

Instantly share code, notes, and snippets.

@imcodetolive
Created June 17, 2013 17:04
Show Gist options
  • Save imcodetolive/5798427 to your computer and use it in GitHub Desktop.
Save imcodetolive/5798427 to your computer and use it in GitHub Desktop.
// Use before yours CSS files
document.documentElement.className = document.documentElement.className.replace(/(\s*|^)no-js(\s*|$)/, "$1js$2");
@imcodetolive
Copy link
Author

Detecção de Javascript

Útil p/ códigos responsivos possibilitando um fallback em casos onde o javascript não esteja habilitado.

  • Deve ser adicionado antes da chamada de qualquer CSS.
  • Para evitar requisições desnecessárias é aconselhável adicionar o código diretamente na tag <script> no head da página.

Exemplo de Uso

<!doctype html>
<!--[if lt IE 7]>      <html class="no-js lt-ie10 lt-ie9 lt-ie8 lt-ie7" lang="pt-BR"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie10 lt-ie9 lt-ie8" lang="pt-BR"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie10 lt-ie9" lang="pt-BR"> <![endif]-->
<!--[if IE 9]>         <html class="no-js lt-ie10" lang="pt-BR"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="pt-BR"> <!--<![endif]-->
<head>
    <meta charset="UTF-8">
    <title>Exemplo</title>

    <script>document.documentElement.className = document.documentElement.className.replace(/(\s*|^)no-js(\s*|$)/, "$1js$2");</script>
    <link href="css/style.css" rel="stylesheet">

</head>
<body>
    <!-- Content ... -->
</body>
</html>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment