Mike
Mike

Reputation: 521

Scroll through multiple HTML pages with javascript

I have the following 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>

It works perfectly in google chrome, but i need to get it working in IE8, because it needs to work on a XP machine.

when i run the following code into IE, i just get a blank screen.

any suggestions??

Upvotes: 0

Views: 1024

Answers (1)

bikeshedder
bikeshedder

Reputation: 7487

You have a trailing comma in your list of dashboards. All IE versions parse JavaScript very strict and don not allow trailing commas in lists and objects.

A very effective way of checking your JavaScript source code is the use of JSHint which reports such kind errors.

You need to fix the following part of the code:

// 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 does not work in IE8: Does not work window.onload in IE8

I would recommend you to use jQuery or any other JavaScript library which handles such browser differences. With jQuery it is as simple as writing.

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

Upvotes: 1

Related Questions