【问题标题】:ASP.NET web app force an iframe to reloadASP.NET Web 应用程序强制 iframe 重新加载
【发布时间】:2022-11-19 14:23:40
【问题描述】:

我不是 .NET Core 开发的新手,但我是 ASP.NET Web 应用程序的新手。

我有一个 Index.cshtml,其中包含以下 iframe:

    <iframe 
      height="800" 
      width="1300" 
      loading="eager" 
      frameBorder="0" 
      scrolling="no" 
      seamless="seamless" 
      allowtransparency="true" 
      src="https://example.com/?page_id=436" 
      title="My site" />

每当页面刷新时,我都需要强制此 iframe 重新加载(而不是从缓存中加载)。在网上,我发现了以下建议:

iframe.src = "https://example.com/?page_id=436?reload="+(new Date()).getTime();

这是我的问题:在 ASP.NET Web 应用程序(使用引导程序)中,我会将此代码放在何处以使其刷新我的 iframe?我对 javascript 比较熟悉(有一段时间没用过),对 ASP.NET 知之甚少,对 bootstrap 几乎一无所知。我非常了解 html/css。

我对在代码中放置这段 javascript 的位置感到困惑,以便它在我刷新页面时始终运行。而且我不知道如何使该代码引用我的特定 iframe。

谢谢!

【问题讨论】:

    标签: javascript c# asp.net-mvc iframe bootstrap-4


    【解决方案1】:

    这段代码刷新了你的iframe。如果你想在页面刷新时刷新它,你应该在页面加载后执行它——在延迟脚本中:

    <script defer>
      iframe.src = "https://example.com/?page_id=436?reload="+(new Date()).getTime();
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-22
      • 2015-09-12
      • 1970-01-01
      • 2019-07-25
      • 1970-01-01
      • 2020-12-11
      • 1970-01-01
      • 2011-12-12
      相关资源
      最近更新 更多