Ad

JS File Is Loaded In HTML (generated Via Markdown) But Not Executing

- 1 answer

The HTML file is generated using Markdown. I have included a JavaScript file in HTML. It is visible that it is loaded in the browser (tried on Mozilla firefox).

See the proof below.

I tested if JS is enabled or not from https://www.whatismybrowser.com/detect/is-javascript-enabled

enter image description here

But somehow, it is not being executed.

Below is my generated HTML

<!DOCTYPE html>
<html lang="en">
  <head>
        <meta charset="UTF-16"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="generator" content="Bootply-JBake-Custom"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-16"/>

<title>Title</title>
    <link target="_blank" rel="nofollow noreferrer" href="/css/bootstrap.min.css" rel="stylesheet">
    <link target="_blank" rel="nofollow noreferrer" href="/css/asciidoctor.css" rel="stylesheet">
    <link target="_blank" rel="nofollow noreferrer" href="/css/base.css" rel="stylesheet">
    <link target="_blank" rel="nofollow noreferrer" href="/css/prettify.css" rel="stylesheet">
    <link target="_blank" rel="nofollow noreferrer" href="/css/styles.css" rel="stylesheet">
    <link target="_blank" rel="nofollow noreferrer" href="/css/animate.css" rel="stylesheet">
<link rel="shortcut icon" target="_blank" rel="nofollow noreferrer" href="favicon.ico">
<script src="/js/jquery-1.11.1.min.js"></script>
<script src="/js/bootstrap.min.js"></script>
<script src="/js/prettify.js"></script>
  </head>
  <body onload="prettyPrint()">
    <div id="wrap">

<div class="navbar navbar-default navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <a target="_blank" rel="nofollow noreferrer" href="/index.html" class="navbar-brand">LOGO</a>
          <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#navbar-main">
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
        </div>
        <div class="navbar-collapse collapse" id="navbar-main">
          <ul class="nav navbar-nav">
                          <li><a target="_blank" rel="nofollow noreferrer" href="/projects/projects.html">Projects</a></li>
              <li><a target="_blank" rel="nofollow noreferrer" href="/about.html">About</a></li>
              <li><a target="_blank" rel="nofollow noreferrer" href="/categories.html">Categories</a></li>
          </ul>
        </div>
      </div>
    </div>
    <div class="container">
        <div class="page-header" id="banner">
            <div class="row">
                <div class="col-lg-8 col-md-7 col-sm-6">
                    <h1>Projects</h1>
                </div>
            </div>
        </div>
         <!-- This script is loading but not executing -->
         <script type="text /javascript" src="projects.js"></script>
<p>Here is the list of projects</p>

    </div>
        </div>
        <div id="push"></div>
    <div id="footer">
      <div class="container">

      </div>
    </div>

  </body>
</html>

projects.js

$(document).ready(function(){
    console.log("ready")
alert("hi");
});

console.log("loaded")
Ad

Answer

<script type="text /javascript" src="projects.js"></script>

Remove the space in type="text /javascript with the result:

<script type="text/javascript" src="projects.js"></script>

This should allow the browser to parse the HTML correctly and load the script.

EDIT: Or remove the type attribute from the <script> tag entirely, as suggested by the comment below.

Ad
source: stackoverflow.com
Ad