0

I'm working on a project where I have 2 iframes displaying different urls. I need to take the first iframe and have that page cycle through 3 or 4 different URLs every 60 seconds. So, for example, it would show http://stackoverflow.com in the iframe for 60 seconds, then it would show http://google.com for 60 seconds, then another site and so on. Below is the code for my split iframe page:

<%@ Page Title="ALM Dashboard View" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="dashboard.aspx.cs" Inherits="WebApplication1.bookings" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
# This is the frame I need to cycle through multiple sites
    <iframe src="https://site1" width="50%" height="1200">
        <p>
            Your browser does not support Iframes</p>
    </iframe>
# This is the static frame
    <iframe src="http://site2" width="49%" height="1200">
        <p>
            Your browser does not support Iframes</p>
    </iframe>
</asp:Content>

How can I one frame to cycle through different urls every 60 seconds?

NoNaMe
  • 6,020
  • 30
  • 82
  • 110

1 Answers1

0

Something like this would work... I randmized the order of the urls, but you could just as easily loop through them. https://jsfiddle.net/jx8kmnq6/

  <script>
    var url = ['website1.com','website2.com','website3.com']
    var length = url.length;
    var d = Math.floor(Math.random() * length) 
    window.setInterval(function(){
      changeUrl();
    }, 60000);

    function changeUrl(){
        $("#iframeId").attr('src',url[d]);  
    }
    </script>
Mark
  • 4,773
  • 8
  • 53
  • 91
  • Thanks for the help! Where would I place this in the code? I'm new to visual studio. Thanks again! – Dominic Zarelli Apr 15 '15 at 16:57
  • I'm assuming you are using ASP.NET MVC, in which case, put this in your view(.cshtml) – Mark Apr 15 '15 at 17:00
  • Here is a fiddle(alerting the change every 6 seconds): https://jsfiddle.net/jx8kmnq6/ – Mark Apr 15 '15 at 17:03
  • Thank you Mark! I'm actually using ASP.NET Web Forms Application (I believe) this was an old project I took over from the last dev who is no longer with the company. I don't have a view.cshtml. All my assets are .aspx and .cs. The file calling the framed pages is dashboard.aspx formatted as listed above. I doesn't sound like this code provided goes into the the dashboard.aspx file. I do have a scripts folder in my project., but again, I'm kind of new to this so I'm not sure how to integrate this script you provided. Any assistance is appreciated. Thanks again for all the info. – Dominic Zarelli Apr 15 '15 at 18:07
  • Put it in the dashboard.aspx file. – Mark Apr 15 '15 at 18:10
  • Thanks, but where exactly? I tried replacing the below content with the script provided and it didn't work - – Dominic Zarelli Apr 15 '15 at 18:37
  • I've done extensive web searching, and I can't seem to figure out where to put this script you provided. I gave each iframe a seperate id using "ID=". The one I need to rotate between URLs is "frame1". Also, I'm not sure how to (or if I even need to) modify the iframe "src=" data in frame1. I've tried removing the 'src=' from frame1 as well, and I'm only left with an empty container. I'm stuck here. Sorry for all the questions... – Dominic Zarelli Apr 16 '15 at 20:57