防止回发时重新加载 Iframe
我有一个带有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
重新加载页面时,其中包含的任何 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.
您可以使用 JavaScript 动态添加 iframe:
它使用 jQuery 将 iframe 添加到 id 为“foo”的元素。但只有当“if”语句中的表达式返回 true 时,它才会添加 iframe。
You could add the iframe dynamically using JavaScript:
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.