我在我的网站上使用Galleria幻灯片,但我注意到一个似乎非常随机的错误。大多数情况下,幻灯片显示正确加载但偶尔会出现此错误:
Uncaught Error: Fatal error: Theme at javascript/themes/classic/galleria.classic.js
could not load, check theme path.
当我重新加载页面时,它都恢复正常。
这是我用来加载它的代码:
<script>
// Load the classic theme
Galleria.loadTheme('javascript/themes/classic/galleria.classic.js');
</script>
我已经四处搜索但仍未找到有效的解决方案。我个人的想法是有一个脚本继续加载,直到成功,因为重新加载页面工作。
我该怎么办?
1在gihub上尝试最新版本: https://github.com/aino/galleria/blob/master/src/galleria.js
2尝试使用脚本标记加载主题:
<script src="javascript/themes/classic/galleria.classic.js"></script>
1在gihub上尝试最新版本: https://github.com/aino/galleria/blob/master/src/galleria.js
2尝试使用脚本标记加载主题:
<script src="javascript/themes/classic/galleria.classic.js"></script>
我尝试使用Galleria时,今天也收到了类似的消息。它只发生在Firefox中。我所做的就是直接添加主题样式表链接 head
。在样式表之后,我也保留了主题脚本链接,以防万一需要它。之后,错误消息消失了,Galleria正在按预期工作。
从错误消息的来源判断,并考虑随机事件,这个问题可能来自加载时简单地达到超时:
Galleria.loadTheme = function( src, options ) {
var loaded = false,
length = _galleries.length,
err = window.setTimeout( function() {
Galleria.raise( "Theme at " + src + " could not load, check theme path.", true );
}, 5000 );
在版本1.2.2中,超时仅为2秒,在上面(1.2.6)中,超时为5秒。因此,升级到更高版本或自定义超时绝对值得一试。
我采用了David指出的方法,使用脚本标记加载主题:
<script src="javascript/themes/classic/galleria.classic.js"></script>
但最终得到了另一个错误(致命错误:主题CSS在20秒后无法加载)。我还建议使用链接标记添加CSS:
<link rel="stylesheet" type="text/css" href="galleria/themes/classic/galleria.classic.css" />
鉴于随机行为,感觉就像一个浏览器错误。更具体地说,浏览器丢失了对基本URL的跟踪。我会从webroot给出完整路径,看看错误是否消失。例如:
Galleria.loadTheme('/gallery/javascript/themes/classic/galleria.classic.js');
如果这没有帮助,请尝试:
try {
Galleria.loadTheme('javascript/themes/classic/galleria.classic.js');
}
catch(e) {
location.reload();
}
但这可以无限。我会尝试找到错误的底部,并从不同的浏览器开始,以排除代码中的错误。
该 初学者指南 说明您加载主题的脚本标记需要 后 html源代码中的图像。您可能已在head标记中添加了脚本标记。指南中的示例:
<body>
<div id="galleria">
<img src="photo1.jpg">
<img src="photo2.jpg">
<img src="photo3.jpg">
</div>
<script>
Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
Galleria.run('#galleria');
</script>
</body>