2

How do I specify the following requirement in my html?

When the computer has access to Internet, the source of MathJax.js is https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js;

When it is offline, and the system is Linux, the source is /MathJax/MathJax.js; if the system is Windows, it is /C:/MathJax/MathJax.js. (It would be even better if I can use environment variable in the local path.)

4

2 回答 2

3

您可以将 MathJax 放在相对于静态 HTML 文件的位置:

<script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js"></script>
<script>
if( !window.MathJax ) {
    document.write(
        '<script type="text\/javascript" src="../lib/MathJax.js"><\/script>'
    );
}
</script>

这样您的实现就独立于操作系统。

另一种选择是根据您的浏览器 URL 设置位置:

<script>
var url= location.protocol == 'http:'? 
         "https://c328740.ssl.cf1.rackcdn.com/mathjax/latest/MathJax.js" :
         "../lib/MathJax.js";
document.write(
    '<script type="text\/javascript" src="' + url + '"><\/script>'
);
</script>
于 2012-06-17T11:27:57.673 回答
2

这些其他页面可能会为您提供一些解决方案的新方法。

第一个演示如何将 url 列表链接在一起,如果前一个脚本失败,则继续尝试加载下一个脚本。

从服务器序列故障转移加载.js?

您需要将围绕 Windows 与 Linux 的逻辑添加到其中。

以下是关于检测网页是否离线运行的一些想法: 检测互联网连接是否离线?

如果您可以提供有关您的应用程序的更多信息,我可能会提出一些更好的建议。这是用户在本地计算机上安装的应用程序吗?这些 JS 文件是如何进入人们的 C:\ 的?安装应用程序时安装了什么?它是如何运行的?是否也安装了本地服务器?还是 html 页面只是从 Web 浏览器中的文件系统运行?

于 2012-06-13T14:08:56.583 回答