开发者

access content in a frame where the docment is never fully loaded

开发者 https://www.devze.com 2023-04-03 20:46 出处:网络
I have an unusual setup.First off, I have a page with frames <html> <head> <title>My Chat</title>

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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号