I have two windows. Parent ( Main.aspx ) and Child.aspx ( Child.aspx ). From the child window I send post data and after receiving the answer I want to work with the element in the parent content.

I got access to the item through

 $(window.opener.document).find("#element"); 

But I ran into another problem, after answering the server as json data I need to close the child window ..

 window.close() 

the window is closed but after that the control over the element is immediately lost.

  $("#btn").click(function () { var m = confirm("Вы уверены что хотите удалить данную запись пользователя? Данные будут удалены безвозвратно."); if (m) { var Username = $("#FieldUsername").val(); var elem = $(window.opener.document).find("#SysMessage"); $.ajax({ url: "Child.aspx/Delete", datatype: "json", cache: false, async: true, contentType: "application/json; charset=utf-8", method: "POST", data: JSON.stringify({ 'Username': Username }), beforeSend: function () { elem.stop().fadeOut(); }, complete: function () { }, success: function (data) { console.log(data.d); data = JSON.parse(data.d); if (data.type == "error") { elem.addClass("error"); } else { $(window.opener.document).find("#__Refresh").click(); elem.addClass("success"); } elem.text(data.str); elem.slideToggle('medium'); elem.delay(5000).fadeOut(800); window.close(); } }); 

And the window closes immediately, although it should last. Tell me what my misunderstanding is, how to be.

  • What does "control over the element" mean? You put off fadeOut for 5 seconds, and close the window immediately. Jquery child window shipped and fadeOut nothing to do. - Igor
  • Igor, thanks for the comment. Even here it doesn’t even have time for 'elem.slideToggle (' medium ');' execute as the window closes. elem (Div) leaves a couple of millimeters and that's it. - haswell
  • Here, thanks for the clarification. The jquery libraries (and global $) in the parent and child windows are independent. Try: var elem = window.opener.$(document).find("#SysMessage"); - Igor
  • Igor, tried it. Now even 2 millimeters diva is not shown) Apparently now he doesn’t see divs at all - haswell
  • Find out, please, whether the search for the required element in the parent window works - alert(elem.length); after var elem = ... - Igor

1 answer 1

You put off fadeOut for 5 seconds, and close the window immediately. Jquery child window is shipped, and fadeOut nothing to do.

The jquery libraries (and global $) in the parent and child windows are independent. Try:

 var elem = window.opener.$(window.opener.document).find("#SysMessage"); 

or easier

 var elem = window.opener.$("#SysMessage");