Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to modify child window DOM using jquery
    primarykey
    data
    text
    <p>I have the following "/tmp/d.html", </p> <pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; var child = null; $(function() { $("#buttonToOpenAnotherWindow").click(function(e) { e.preventDefault(); child = window.open('file:///tmp/a.html'); $(child.document).ready(function(){ //alert('child'); $("body", child.document).append( 'ffffffffffffffffffffffffffffff'); }); }); }); &lt;/script&gt; &lt;a href="#openAnother" id="buttonToOpenAnotherWindow"&gt;Open Another Window&lt;/a&gt; </code></pre> <p>(only showing the main parts) my intention is to click the button, then it opens up another page , then I'll modify that child window page. when I tried this out on firefox 23.0 on linux, I do see the second window opened, its page showing "fffffffffffffffffffffffff", but then quickly the original content of "/tmp/a.html" replaced the page, and the "ffffffffffffffff" is gone. somehow if I put a debugger break before append(), it works as I intended.</p> <p>my end goal for doing this is to fire up a child window, modify the child window with jquery so that it automatically clicks a button (to download one file from that page), then after the .ajax() download is completed, close the child window---- to do this I need to get a handle to the deferred obj returned by .ajax(), from the parent window. but one end blocker I may run into is cross-domain: if I open another domain in child window, the parent window won't be able to modify its content. then I have to use greasemonkey in the child window, but then I won't be able to wait on the deferred obj from the child window, and close the window after download completion. </p> <p>Thanks Yang</p> <p>---- update</p> <p>after the onload() actually makes the child run, I ran into cross-domain issues, now I tried the following code from child window:</p> <pre><code> $('body', window.opener.document).append('child child child'); $('#closechild', window.opener.document).trigger('click'); </code></pre> <p>weirdly, the first line worked, but the second doesn't. my intention was that the "#closechild" button in parent would call childwindow.close(). this button, when clicked in main window manually, does work. but it doesn't work when called from child window as above</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload