使用 javascript 滚动浏览多个 HTML 页面

Scroll through multiple HTML pages with javascript

本文关键字:HTML 页面 浏览 javascript 滚动 使用      更新时间:2023-09-26

我有以下 HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dashboard Example</title>
<style type="text/css">
body, html { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; }
iframe { border: none; }
</style>
<script type="text/javascript">
var Dash = {
    nextIndex: 0,
    dashboards: [
        {url: "C:'CarPositionBrisbane.HTML", time: 5},
        {url: "C:'CarPositionCaboolture.HTML", time: 5},
        {url: "C:'CarPositionLogan.HTML", time: 5},
        {url: "C:'CarPositionWarwick.HTML", time: 5},
        {url: "C:'CarPositionHobart.HTML", time: 5},
        {url: "C:'CarPositionToowoomba.HTML", time: 5},
        {url: "C:'CarPositionIpswich.HTML", time: 5},
        {url: "C:'CarPositionYeppoon.HTML", time: 5},

    ],
    display: function()
    {
        var dashboard = Dash.dashboards[Dash.nextIndex];
        frames["displayArea"].location.href = dashboard.url;
        Dash.nextIndex = (Dash.nextIndex + 1) % Dash.dashboards.length;
        setTimeout(Dash.display, dashboard.time * 1000);
    }
};
window.onload = Dash.display;
</script>
</head>
<body>
<iframe name="displayArea" width="100%" height="100%"></iframe>
</body>
</html>

它在谷歌浏览器中完美运行,但我需要让它在IE8中工作,因为它需要在XP机器上运行。

当我在IE中运行以下代码时,我只会得到一个空白屏幕。

有什么建议吗??

仪表板

列表中有一个尾随逗号。所有IE版本都非常严格地解析JavaScript,并且不允许在列表和对象中使用尾随逗号。

检查JavaScript源代码的一个非常有效的方法是使用JSHint,它报告这种错误。

您需要修复代码的以下部分:

// quoting of the "'" in the URLs fixed.
dashboards: [
    {url: "C:''CarPositionBrisbane.HTML", time: 5},
    {url: "C:''CarPositionCaboolture.HTML", time: 5},
    {url: "C:''CarPositionLogan.HTML", time: 5},
    {url: "C:''CarPositionWarwick.HTML", time: 5},
    {url: "C:''CarPositionHobart.HTML", time: 5},
    {url: "C:''CarPositionToowoomba.HTML", time: 5},
    {url: "C:''CarPositionIpswich.HTML", time: 5},
    {url: "C:''CarPositionYeppoon.HTML", time: 5} // <--- comma removed
],

window.onload 在 IE8 中不起作用:在 IE8 中 window.onload 不起作用

我建议您使用 jQuery 或任何其他处理此类浏览器差异的 JavaScript 库。使用jQuery,它就像编写一样简单。

$(function() {
    // insert code here that should be run when the document is ready.
});