Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
62 views
in Technique[技术] by (71.8m points)

javascript - Script tag doesn't load all of the time

So, I have this code but it doesn't load all of the time. Why?

<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
      $(function() {
        $("#header").load("/components/navbar.html");
        $("#footer").load("/components/footer.html");
      });
    </script>
  </head>
  <body>
    <div id="header"></div>

Here's the source code: https://glitch.com/edit/#!/sargentcoding-official?path=testindex.html%3A45%3A27

Here's the standard page structure:

  <!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta title="Sargent Coding" />
    <meta charset="utf-8" />
    <meta property="og:title" content="Sargent Coding" />
    <meta property="og:site_name" content="Sargent Coding" />
    <meta property="og:description" content="Where ambition comes to life." />
    <meta
      property="og:image"
      content="https://cdn.glitch.com/5f5ab845-2cb8-4210-b34a-03b1f032163a%2FScratch%20Stuff%20(77)-svg.svg?v=1607718360358"
    />
    <meta property="og:image:width" content="500" />
    <meta property="og:image:height" content="500" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title id="titleHtml">Sargent Coding</title>
    <link
      rel="icon"
      type="image/png"
      href="https://cdn.glitch.com/5f5ab845-2cb8-4210-b34a-03b1f032163a%2F1a81804e-7a4e-4dd6-9c14-43a2bdb9061b_favicon.png?v=1607718475017"
    />
    <link
      href="https://fonts.googleapis.com/css2?family=Overpass+Mono"
      rel="stylesheet"
    />
    <link
      href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap"
      rel="stylesheet"
    />
    <link rel="stylesheet" href="/style.css" />
    <script
      src="https://twemoji.maxcdn.com/v/latest/twemoji.min.js"
      crossorigin="anonymous"
    ></script>
    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
    <script>
      $(function() {
        $("#header").load("/components/navbar.html");
        $("#footer").load("/components/footer.html");
      });
    </script>
  </head>
  <body>
    <div id="header"></div>

  <!-- Header above. -->
   
  <!-- CODE GOES HERE -->

  <!-- Footer below. -->

    <div id="footer"></div>
  </body>
</html>

I'm not using jQuery for any reason. I just don't know what I'm doing.

question from:https://stackoverflow.com/questions/65833020/script-tag-doesnt-load-all-of-the-time

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have not found to error, this code is properly working in a local browser (Chrome).

Maybe, you are run this code in the same site: https://glitch.com/edit/#!/sargentcoding-official?path=testindex.html%3A45%3A27

site is protected by hidden code and this reason, you have this code but it doesn't load all of the time

<!DOCTYPE html>
<html lang="en" dir="ltr">

<head>
  <meta title="Sargent Coding" />
  <meta charset="utf-8" />
  <meta property="og:title" content="Sargent Coding" />
  <meta property="og:site_name" content="Sargent Coding" />
  <meta property="og:description" content="Where ambition comes to life." />
  <meta property="og:image" content="https://cdn.glitch.com/5f5ab845-2cb8-4210-b34a-03b1f032163a%2FScratch%20Stuff%20(77)-svg.svg?v=1607718360358" />
  <meta property="og:image:width" content="500" />
  <meta property="og:image:height" content="500" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title id="titleHtml">Sargent Coding</title>
  <link rel="icon" type="image/png" href="https://cdn.glitch.com/5f5ab845-2cb8-4210-b34a-03b1f032163a%2F1a81804e-7a4e-4dd6-9c14-43a2bdb9061b_favicon.png?v=1607718475017" />
  <link href="https://fonts.googleapis.com/css2?family=Overpass+Mono" rel="stylesheet" />
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700" rel="stylesheet" />
  <script src="https://twemoji.maxcdn.com/v/latest/twemoji.min.js" crossorigin="anonymous"></script>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
  <script>
    $(function() {
      $("#header").load("/components/navbar.html");
      $("#footer").load("/components/footer.html");
    });
  </script>
</head>

<body>
  <div id="header"></div>

  <!-- Header above. -->
  <img src="https://cdn.glitch.com/5f5ab845-2cb8-4210-b34a-03b1f032163a%2FUntitled%20drawing.svg?v=1611158518090" style="position:absolute; height:17.5em; top: 5.125em; right: 1.5em;" />
  <div>
    <p>&nbsp;<br /><br /></p>
    <h1 class="reallybig">
      <br />
      Where <font color="#4a86e8">ambition</font><br />comes to
      <font color="#21d58e">life</font>.
    </h1>
  </div>
  <a href="/amexpauto.html">
    <div class="frontPageBoxes amexpautoAd"></div>
  </a>
  <br />
  <a href="/amexpauto.html">
    <div class="frontPageBoxes obuioAd"></div>
  </a>

  <!-- Footer below. -->

  <div id="footer"></div>
</body>

</html>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...