如何更新 jQuery 帖子内子 iFrame 的整个 html(标题和正文)
我有一个 Firefox 聊天网页,其结构如下
..... 外部 HTML
-----|......框架集框架
------------|.... .. header: 包含 jQuery post 已返回的数据: rdata = new_iFrame_html_str, 应该更新的 iFrame 的整个 html 字符串
------------|...... iFrame
---- ----------------|...... 标头:包含 jQuery
--------------------|.. ....正文:依赖于标题 jQuery 才能正常运行的聊天消息
问题:我无法使此 jQuery 帖子正常工作,即我找不到此帖子更新整个 iFrame(标题+正文)。
我用javascript和jQuery尝试过但失败了:
- top.frames['framesetFrame_name'].document.getElementById('iframe_id').contentDocument.body.innerHTML = new_iFrame_html_str;
- 我不喜欢这样,因为它只更改正文,而不更改标头,因此无法显示 jQuery 生成的行为
- top.frames['framesetFrame_name'].document.getElementById('iframe_bucinid').contentWindow.location.reload();
- 我不想重新加载,因为重新加载会使 iFrame 闪烁,这对聊天程序不利
- top.frames['framesetFrame_name'].document.getElementById('iframe_id').contents().html = new_iFrame_html_str;
- 没有更新任何显示:(
- top.frames['framesetFrame_name'].document.getElementById('iframe_id').contentWindow.location.href = new_iFrame_html_str;
- 这实际上是错误的形式,因为它应该是 = url_of_new_content
- $( top.frames['framesetFrame_name'].document.getElementById('iframe_id') ).html( new_iFrame_html_str ) ;
- 不更新任何显示 :(
I have a chat webpage for Firefox that is structured like this
..... Outer HTML
-----|......Frameset Frame
------------|...... header: contains jQuery post has returned data: rdata = new_iFrame_html_str, the entire html string of the iFrame that should be updated
------------|...... iFrame
--------------------|...... header: contains jQuery
--------------------|...... body: chat messages that depends on the header jQuery to behave properly
QUESTION: I can't this jQuery post to work, i.e. I can't find a way for this post to update the ENTIRE iFrame (header + body).
Things I've tried and FAILED with javascript and jQuery:
- top.frames['framesetFrame_name'].document.getElementById('iframe_id').contentDocument.body.innerHTML = new_iFrame_html_str;
- I don't like this because it's only changing the body, not the header, so the behavior generated from jQuery can't be shown
- top.frames['framesetFrame_name'].document.getElementById('iframe_bucinid').contentWindow.location.reload();
- I do not want to reload because a reload makes the iFrame flicker, bad for a chat program
- top.frames['framesetFrame_name'].document.getElementById('iframe_id').contents().html = new_iFrame_html_str;
- Not updating anything that shows :(
- top.frames['framesetFrame_name'].document.getElementById('iframe_id').contentWindow.location.href = new_iFrame_html_str;
- This is actually the wrong form here, because it should be = url_of_new_content
- $( top.frames['framesetFrame_name'].document.getElementById('iframe_id') ).html( new_iFrame_html_str ) ;
- Not updating anything that shows :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,下面这两行是获得我想要的内容的迂回方式(刷新子 iframe 的整个 HTML)。然而,即使刷新了头部,iframe 头部的 jQuery 仍然没有执行。
有谁知道为什么?
第一行去掉了“”和“”,因为我们正在更新 HTML 的innerHTML
So these two lines below are a roundabout way to get what I wanted (refresh the entire HTML of child iframe). However, the jQuery in the head of the iframe is still not executed, even though the head is refreshed.
Does anyone know why?
The first line takes out the "" and "" since we're updating HTML's innerHTML