Mohammad Halawi
Mohammad Halawi

Reputation: 67

javascript in a html file works fine in my live server using VS Code but if i open the .html file locally it doesn't work

The code basically is for making a Quiz. I'm using quiz maker and copied the code that they gave me and altered it a bit. But the thing is, it works fine if I launch it in Vs code using live server. However if I open the file(.html file) from the folder nothing works. Also I have this error on local "Failed to load resource: net::ERR_FILE_NOT_FOUND".

    <script>
      (function (i, s, o, g, r, a, m) {
        var ql = document.querySelectorAll('A[quiz],DIV[quiz],A[data-quiz],DIV[data-quiz]');
        if (ql) {
          if (ql.length) {
            for (var k = 0; k < ql.length; k++) {
              ql[k].id = 'quiz-embed-' + k;
              ql[k].href =
                "javascript:var i=document.getElementById('quiz-embed-" +
                k +
                "');try{qz.startQuiz(i)}catch(e){i.start=1;i.style.cursor='wait';i.style.opacity='0.5'};void(0);";
            }
          }
        }
        i['QP'] = r;
        (i[r] =
          i[r] ||
          function () {
            (i[r].q = i[r].q || []).push(arguments);
          }),
          (i[r].l = 1 * new Date());
        (a = s.createElement(o)), (m = s.getElementsByTagName(o)[0]);
        a.async = 1;
        a.src = g;
        m.parentNode.insertBefore(a, m);
      })(window, document, 'script', '//cdn.poll-maker.com/quiz-embed-v1.js', 'qp');
    </script>
    <script>
      function closeBanner() {
        const trial = document.querySelector('.trial-box');
        trial.style.display = 'none';
      }
    </script>
<a
      onclick="closeBanner()"
      data-quiz="Q81HSFC7B"
      data-type="5"
      data-fullscreen="true"
      href="https://www.quiz-maker.com/Q81HSFC7B"
      style="
        display: inline-block;
        text-align: left;
        margin: 0 auto;
        width: 100%;
        max-width: 824px;
        box-sizing: border-box;
        text-decoration: none;
        padding: 1em;
        border: 1px solid #ccc;
        color: inherit;
      "
      ><div
        style="
          display: block;
          font-family: sans-serif;
          font-size: 1.5em;
          line-height: 40px;
          color: inherit;
        "
      >
        English Assessment Exam
      </div></a
    >

Upvotes: 1

Views: 352

Answers (1)

Maverick Fabroa
Maverick Fabroa

Reputation: 1173

Failed to load resource: net::ERR_FILE_NOT_FOUND means that some resource attached in your html doesn't exist.

Instead of //cdn.poll-maker.com/quiz-embed-v1.js, just replace it to https://cdn.poll-maker.com/quiz-embed-v1.js

Upvotes: 2

Related Questions