Reputation: 35557
I have the following code that I am 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 it's a routine to cycle through urls in an array into an iframe. My problem occurs when I set parent.document.getElementById("iframe1").src
to a url; it works for the first but it doesn't seem to cycle through 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 the parent.document
call, all works fine.
Is it losing the focus of the javascript when I issue the parent.document
call?
Any ideas on how to bring focus back to this javascript code when calling a parent.document
?
I am using ie6.
Upvotes: 3
Views: 448
Reputation: 28142
Have you tried using 'top' instead of 'parent'?
top.document.getElementById("iframe1").src = dashboard.url;
http://www.w3schools.com/jsref/prop_win_top.asp
That way you have an absolute reference and don't have to worry about which window it actually is in.
Upvotes: 0
Reputation: 726
This code change should work. You need to give iframe a name and secondly, I didnt test it in IE6, but works in 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>
Upvotes: 1