访问文档从未完全加载的框架中的内容

发布于 2024-12-03 17:28:19 字数 1194 浏览 9 评论 0原文

我有一个不寻常的设置。首先,我有一个带有框架的页面

<html>

 <head>

  <title>My Chat</title>

</head>

 <frameset id="resize" rows="*,135">

  <frame name="Main" src="/chat/stream.pl">

  <frame name="Comm" src="/chat/realm.pl">

 </frameset>

</html> 

主框架包含不断从服务器流式传输的内容。问题是浏览器将此视为页面从未完成加载,并且不会发生超时。页面上,有这样的内容。

<table class="PSTPRI" cellspacing="3" cellpadding="2">

  <tr>

   <td>

    <IMG SRC="http://mysite.com/myimage.jpg" HEIGHT="470" WIDTH="550" ALIGN="left" BORDER="0">

    <!-HEAD-->  lots of text for the post header <!-POST-->

    <p><span style="font-size: 11px; color: #FFFFFF; font-family: Verdana;">the post text<BR></span></p>

   </td>

  </tr>

  <!-- ...more content here, each post is a new TR  -->
</table>

我希望能够将实时事件绑定到此内容中的图像。警告 - 我将其作为 chrome 扩展,将其分配给包含框架集的页面。该脚本有效,我只需要能够将事件附加到图像即可。现在,这是我想要附加的示例事件。

$('table.PSTPRI td img').live('click', function () {
    alert('test');
});

但问题是 1)我不知道如何在正确的上下文中选择图像,2)我需要选择器假设文档从未加载过,即使显示了对象在屏幕上。

I have an unusual setup. First off, I have a page with frames

<html>

 <head>

  <title>My Chat</title>

</head>

 <frameset id="resize" rows="*,135">

  <frame name="Main" src="/chat/stream.pl">

  <frame name="Comm" src="/chat/realm.pl">

 </frameset>

</html> 

The main frame has content that is continually streaming from the server. The problem is that the browser treats this as if the page is never done loading, and no timeout occurs. On the page, there is content like this.

<table class="PSTPRI" cellspacing="3" cellpadding="2">

  <tr>

   <td>

    <IMG SRC="http://mysite.com/myimage.jpg" HEIGHT="470" WIDTH="550" ALIGN="left" BORDER="0">

    <!-HEAD-->  lots of text for the post header <!-POST-->

    <p><span style="font-size: 11px; color: #FFFFFF; font-family: Verdana;">the post text<BR></span></p>

   </td>

  </tr>

  <!-- ...more content here, each post is a new TR  -->
</table>

I want to be able to bind a live event to the image in this content. The caveat - I am making this as a chrome extension that I am assigning to the page containing the frameset. The script works, I just need to be able to attach an event to the image. for now, here is my sample event that I want to attach.

$('table.PSTPRI td img').live('click', function () {
    alert('test');
});

The problem though, is that 1) I don't know how to select the image in the correct context, and 2) I need the selector to work on the assumption that the document isn't ever loaded, even though the objects are shown on the screen.

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

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

发布评论

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

评论(1

孤芳又自赏 2024-12-10 17:28:19

好吧,您的问题中缺少一些细节,所以如果这不是您寻求的答案,请原谅我。

我相信您正在尝试在“带框架的页面”中注入一些脚本。
如果这是正确的,您所要做的就是在 content_scripts 部分下的 manifest.json 中设置两个属性,如下所示:

"content_scripts": [
    {
      "matches": ["Match pattern for your page with frames"],
      "js": ["main_script.js"],
      "all_frames": true,
      "run_at": "document_start"
    },
    {...}
  ]

all_frames:控制内容脚本是否在所有帧中运行
匹配的页面,或仅顶部框架。


run_at:控制js中的文件何时注入。可以是
“文档开始”、“文档结束”或“文档空闲”。默认为
“文档_空闲”。

在“document_start”的情况下,文件在任何之后注入
来自 css 的文件,但在构建任何其他 DOM 或任何其他之前
脚本已运行。

参考:
http://code.google.com/chrome/extensions/content_scripts.html

Well, there are some details missing in your question, so forgive me if this is not the answer you seek.

I believe that you are trying to inject some scripts in your "page with frames".
If that's right, all you have to do is set two properties in manifest.json under content_scripts section as follows:

"content_scripts": [
    {
      "matches": ["Match pattern for your page with frames"],
      "js": ["main_script.js"],
      "all_frames": true,
      "run_at": "document_start"
    },
    {...}
  ]

all_frames: Controls whether the content script runs in all frames of
the matching page, or only the top frame.


run_at: Controls when the files in js are injected. Can be
"document_start", "document_end", or "document_idle". Defaults to
"document_idle".

In the case of "document_start", the files are injected after any
files from css, but before any other DOM is constructed or any other
script is run.

References:
http://code.google.com/chrome/extensions/content_scripts.html

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