防止回发时重新加载 Iframe

发布于 2024-08-11 16:20:12 字数 291 浏览 1 评论 0原文

我有一个带有一个 iframe 和一个按钮的网页。

在页面加载事件中,

if (!Page.IsPostBack)
{
string sDocUrl = //some doucmen url
Iframe1.Attributes["src"] = sDocUrl;
}

当页面重新加载(通过单击按钮)时,此 iframe 正在被加载 也重新加载了。这个 iframe 有静态数据,不需要 每次我单击按钮时都会重新加载。有没有办法预防 重新加载webform时iframe要重新加载吗?

I have a webpage with one iframe and a button.

On Page Load event,

if (!Page.IsPostBack)
{
string sDocUrl = //some doucmen url
Iframe1.Attributes["src"] = sDocUrl;
}

When the page is reloaded (by clicking a button), this iframe is being
reloaded too. This iframe has a static data and doesn't need to be
reloaded everytime when I click a button. Is there a way to prevent
iframe to be reloaded when webform is reloaded?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

坠似风落 2024-08-18 16:20:12

重新加载页面时,其中包含的任何 iframe(就像任何脚本、图像等)都将始终重新加载。抱歉,没有解决这个问题的方法,只是因为整个页面实际上会重新加载。

When a page is reloaded, any iframes contained in it (just as any scrips, images, anything) will always be reloaded. There's no working around that, sorry, simply because the entire page actually reloads.

牵你的手,一向走下去 2024-08-18 16:20:12

您可以使用 JavaScript 动态添加 iframe:

if (!Page.IsPostBack)
{
    $('#foo').append('<iframe src="' + sDocUrl + '"></iframe>');
}

它使用 jQuery 将 iframe 添加到 id 为“foo”的元素。但只有当“if”语句中的表达式返回 true 时,它​​才会添加 iframe。

You could add the iframe dynamically using JavaScript:

if (!Page.IsPostBack)
{
    $('#foo').append('<iframe src="' + sDocUrl + '"></iframe>');
}

That uses jQuery to add the iframe to an element with an id of "foo". But it will only add the iframe if the expression in the 'if' statement returns true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文