Search code examples
javascriptjqueryiframeframeset

what is the jQuery / javascript context of a frame within an iframe?


Let me preface this with... I have referenced this question/answers and it seems to contain clues, but i'm still missing the whole picture

Run JQuery in the context of another frame

Essentially, the structure of the index page is this

<html>
<body>
  <div class="frames-wrap">
      <iframe id="this-iframe" src="location.php">

      </iframe>
  </div>
</body>
</html>

location.php then contains a frameset (ahem, not my idea...) that has two frames that are set up like so...

<frameset cols="350,*">
  <frame src="search.php" id="frame_search" name="search"/>
  <frame src="edit.php" id="frame_edit" name="edit" />
</frameset>  

if i want to manipulate objects between the index page and these elements how would i go about this?

I keep thinking the context should be something similar to window.parent.frames[0].document... what else am i missing?


Solution

  • Preface: You wont be able to access the iframes contents unless it originates from the same domain.

    To select elements in your iframe you could use a jQuery call like this

    element = $("#this_iframe").contents().find("#frame_search")
    

    The key is to use the contents() function. See Traversing/contents