0

我正在做一个项目,我有 2 个 iframe 显示不同的 url。我需要获取第一个 iframe 并让该页面每 60 秒循环通过 3 或 4 个不同的 URL。因此,例如,它会在 iframe 中显示http://stackoverflow.com 60 秒,然后会显示http://google.com 60 秒,然后是另一个站点,依此类推。以下是我的拆分 iframe 页面的代码:

<%@ 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>

如何每 60 秒通过一帧循环浏览不同的网址?

4

1 回答 1

0

像这样的东西会起作用......我随机化了网址的顺序,但您可以轻松地循环浏览它们。 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>
于 2015-04-15T13:28:27.710 回答