Mohammad Saberi
Mohammad Saberi

Reputation: 13166

How to put something inside new opened window using jQuery

I have 2 files. current.htm and new.htm.

I used window.open() in current.htm to open other file and specified a name to the new one.

Now, I need to put some text in a certain part of new.htm (for example a <div>).

How can I do it with jQuery?

Upvotes: 1

Views: 2131

Answers (4)

Pavan
Pavan

Reputation: 4339

If you want to modify the DOM of your child window, try the below

$(childWindow.document).ready(function() { 
   var $theDiv = $(childWindow.document).contents().find('#yourdiv');
   // $theDiv.WhateverYouWantToDo();
}); 

Upvotes: 1

ridecar2
ridecar2

Reputation: 1957

What you do is pull the changes across with window.opener as shown here http://forum.jquery.com/topic/how-do-i-manipulate-a-dom-in-an-window-open

EDIT for explanation:

in a script block in current.htm you could have:

function editChild() {
    // Do stuff with DOM here.
}

and in new.htm:

$(document).ready(function() {window.opener.editChild(); } );

Hope this helps.

Upvotes: 5

In new.htm: $("div#myDiv").html("This is some text").

Upvotes: 0

Chris Kempen
Chris Kempen

Reputation: 9661

Why not just put <script> ... </script> in new.htm to dynamically edit the text? Or have I missed something?

Upvotes: 0

Related Questions