var Dash = { nextIndex: 0, dashboards:...">

Javascript loss focus code

I have the following code I'm playing with:

<script type="text/javascript">

var Dash = {
    nextIndex: 0,
    dashboards: [
        {url: 'http://www.google.com', time: 5},
        {url: 'http://www.yahoo.com', time: 10}
    ],

    display: function()
    {
        var dashboard = Dash.dashboards[Dash.nextIndex];
        parent.document.getElementById("iframe1").src = dashboard.url;
        Dash.nextIndex = (Dash.nextIndex + 1) % Dash.dashboards.length;
        setTimeout(Dash.display, dashboard.time * 1000);
    }
};

window.onload = Dash.display;

</script>

Basically, this is the usual procedure for looping URLs to an array in an iframe. My problem arises when I install parent.document.getElementById("iframe1").srcon url; it works for the first, but it doesn't seem to move on to the next.

However, if I create an iframe in the same context of this javascript, say iframe2 and instead just use:

        document.getElementById("iframe2").src = dashboard.url;

without a call parent.document, everything works fine.

Does javascript lose focus when calling a call parent.document?

Any ideas on how to get the focus back to this javascript code when called parent.document?

I am using ie6.

+3
source share
2

. iframe , -, IE6, IE7.

<script type="text/javascript">

var Dash = {
    nextIndex: 0,
    dashboards: [
    {url: 'http://www.rediff.com', time: 5},
    {url: 'http://www.google.com', time: 10}
    ],

    display: function()
    {
    var dashboard = Dash.dashboards[Dash.nextIndex];
    parent.frames["fname"].location.href = dashboard.url;
        window.focus();
    Dash.nextIndex = (Dash.nextIndex + 1) % Dash.dashboards.length;
    setTimeout(Dash.display, dashboard.time * 1000);
    }
};

window.onload = Dash.display;

</script>
+1

'top' 'parent'?

top.document.getElementById("iframe1").src = dashboard.url;

http://www.w3schools.com/jsref/prop_win_top.asp

, , , .

0

Source: https://habr.com/ru/post/1752375/


All Articles