为什么我可以'不要在任何主机上使用javascript(PC除外)

Why I can't use javascript any hosting (Except PC)

本文关键字:javascript 除外 PC 主机 任何 我可以 为什么      更新时间:2024-06-02

我有这个源代码:

<!DOCTYPE html>
<head>
  <script type="text/javascript" src="http://community.wikidot.com/local--files/howto:sortable-tables-js/sorttable.js"></script>
  <style type="text/css">
  th, td {
    padding: 3px !important;
  }
  table.sortable thead {
      background-color:#eee;
      color:#666666;
      font-weight: bold;
      cursor: default;
  }
  </style>
</head>
<body>
<table class="sortable">
<thead>
<tr>
<td><strong>Name</strong></td>
<td><strong>Salary</strong></td>
<td><strong>Extension</strong></td>
<td><strong>Start Date</strong></td>
<td><strong>Start Date(American)</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td>Bloggs, Fred</td>
<td>$12000.00</td>
<td>1353</td>
<td>18/08/2003</td>
<td>08/18/2003</td>
</tr>
<tr>
<td>Shakespeare, Hamnet</td>
<td>$9000</td>
<td>9005</td>
<td>01/01/2002</td>
<td>01/01/2002</td>
</tr>
<tr>
<td>Mbogo, Arnold</td>
<td>$32010.12</td>
<td>2755</td>
<td>09/08/1998</td>
<td>08/09/1998</td>
</tr>
<tr>
<td>Fitz, Marvin</td>
<td>$3300</td>
<td>5554</td>
<td>22/05/1995</td>
<td>05/22/1995</td>
</tr>
<tr>
<td>Turvey, Kevin</td>
<td>$191200.00</td>
<td>2342</td>
<td>02/05/1979</td>
<td>05/02/1979</td>
</tr>
<tr>
<td>Shakespeare, Bill</td>
<td>$122000.00</td>
<td>3211</td>
<td>12/11/1961</td>
<td>11/12/1961</td>
</tr>
</tbody>
<tfoot>
<tr>
<td><strong>TOTAL</strong></td>
<td>$369510</td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
</body>
</html>

我在电脑上对表格进行排序可以很好地工作,但当我把这个HTML文件上传到主机时,排序表格就不起作用了。主机会为我禁用Javascript吗?

我用GoogleDrive做主机。我试过Dropbox,但它也不起作用。

示例表:https://2cdf7d8230e2b51a89d897a354b906bcb02dfca8.googledrive.com/host/0B_WPAWweGO9mfnpGM1FNR0pLZ1VEQlJHQzNJMGRrd3hwaW9WTjg0aE91MG1uZkhCQzJWRzQ/heroes-data.html

Chrome报告:

Mixed Content: The page at 'https://2cdf7d8230e2b51a89d897a354b906bcb02dfca8.googledrive.com/host/0B_WP…pGM1FNR0pLZ1VEQlJHQzNJMGRrd3hwaW9WTjg0aE91MG1uZkhCQzJWRzQ/heroes-data.html' was loaded over HTTPS, but requested an insecure script 'http://community.wikidot.com/local--files/howto:sortable-tables-js/sorttable.js'. This request has been blocked; the content must be served over HTTPS.

总结:This request has been blocked; the content must be served over HTTPS.

您的Google Drive网站在HTTPS下运行,但请求的javascript是通过HTTP链接的。你需要匹配协议,否则浏览器会变得可疑并阻止链接的脚本。

我假设Google Drive文件必须通过HTTPS提供,所以你不能改变这一点。但您可以更改的是链接脚本的协议。

<script type="text/javascript" src="//community.wikidot.com/local--files/howto:sortable-tables-js/sorttable.js"></script>

我从src URL中删除了http:,因此它是"无协议的",并将适应于当前文档中的任何内容,在本例中为HTTPS。现在它应该匹配并正确加载。你也很幸运,提供文件的网站能够通过HTTPS提供服务(他们有SSL证书)。

您应该在浏览器控制台中看到此错误:

 Mixed Content: The page at 'https://2cdf7d8230e2b51a89d897a354b906bcb02dfca8.googledrive.com/host/0B_WP…pGM1FNR0pLZ1VEQlJHQzNJMGRrd3hwaW9WTjg0aE91MG1uZkhCQzJWRzQ/heroes-data.html' was loaded over HTTPS, but requested an insecure script 'http://community.wikidot.com/local--files/howto:sortable-tables-js/sorttable.js'. This request has been blocked; the content must be served over HTTPS.

这意味着你使用的js库是用http调用的,而html页面是用https提供的。你只需要这样更改库url方案:https://community.wdfiles.com/local--files/howto%3Asortable-tables js/sortable.js

尝试这个

<!DOCTYPE html>
<head>
  <script type="text/javascript" src="//community.wikidot.com/local--files/howto:sortable-tables-js/sorttable.js"></script>
  <style type="text/css">
  th, td {
    padding: 3px !important;
  }
  table.sortable thead {
      background-color:#eee;
      color:#666666;
      font-weight: bold;
      cursor: default;
  }
  </style>
</head>
<body>
<table class="sortable">
<thead>
<tr>
<td><strong>Name</strong></td>
<td><strong>Salary</strong></td>
<td><strong>Extension</strong></td>
<td><strong>Start Date</strong></td>
<td><strong>Start Date(American)</strong></td>
</tr>
</thead>
<tbody>
<tr>
<td>Bloggs, Fred</td>
<td>$12000.00</td>
<td>1353</td>
<td>18/08/2003</td>
<td>08/18/2003</td>
</tr>
<tr>
<td>Shakespeare, Hamnet</td>
<td>$9000</td>
<td>9005</td>
<td>01/01/2002</td>
<td>01/01/2002</td>
</tr>
<tr>
<td>Mbogo, Arnold</td>
<td>$32010.12</td>
<td>2755</td>
<td>09/08/1998</td>
<td>08/09/1998</td>
</tr>
<tr>
<td>Fitz, Marvin</td>
<td>$3300</td>
<td>5554</td>
<td>22/05/1995</td>
<td>05/22/1995</td>
</tr>
<tr>
<td>Turvey, Kevin</td>
<td>$191200.00</td>
<td>2342</td>
<td>02/05/1979</td>
<td>05/02/1979</td>
</tr>
<tr>
<td>Shakespeare, Bill</td>
<td>$122000.00</td>
<td>3211</td>
<td>12/11/1961</td>
<td>11/12/1961</td>
</tr>
</tbody>
<tfoot>
<tr>
<td><strong>TOTAL</strong></td>
<td>$369510</td>
<td></td>
<td></td>
<td></td>
</tr>
</tfoot>
</table>
</body>
</html>