【问题标题】:C# asp page to display multiple urls on a timerC# asp页面在计时器上显示多个url
【发布时间】:2015-06-19 09:29:51
【问题描述】:

我正在做一个项目,我有 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 秒通过一帧循环浏览不同的网址?

【问题讨论】:

  • 你的问题是什么?
  • 对不起。我想知道如何让一个 iframe 窗口每 x 秒(例如 60 秒)显示一个不同的 URL。我希望这更清楚。谢谢。

标签: c# asp.net iframe navigateurl


【解决方案1】:

这样的事情会起作用...我随机化了网址的顺序,但您也可以轻松地遍历它们。 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>

【讨论】:

  • 感谢您的帮助!我将把它放在代码中的什么位置?我是视觉工作室的新手。再次感谢!
  • 我假设您使用的是 ASP.NET MVC,在这种情况下,请将其放在您的视图中(.cshtml)
  • 这是一个小提琴(每 6 秒提醒更改):jsfiddle.net/jx8kmnq6
  • 谢谢马克!我实际上正在使用 ASP.NET Web 窗体应用程序(我相信)这是一个旧项目,我从不再与公司合作的最后一个开发人员那里接手。我没有 view.cshtml。我所有的资产都是 .aspx 和 .cs。调用框架页面的文件是上面列出的格式的dashboard.aspx。我听起来不像提供的此代码进入dashboard.aspx 文件。我的项目中确实有一个脚本文件夹。但同样,我对此有点陌生,所以我不确定如何集成您提供的这个脚本。任何帮助表示赞赏。再次感谢您提供的所有信息。
  • 放到dashboard.aspx文件中。
猜你喜欢
  • 1970-01-01
  • 2017-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-12
  • 2015-11-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多