Aditya Yenduri Aditya Yenduri - 1 year ago 72
ASP.NET (C#) Question as modal popup behaviour


is depreciated in chrome, So I am using instead. But the problem is that after opening Child window I want my parent window to be disabled and if I click on Parent window it should focus on child window.

I tried with some body attributes like
events it is working to some extent but if there is any button on parent and if I click its respective event is getting invoked.

For now I am disabling the parent window events as below when I am opening Child window.

$('body').css({ 'opacity': 0.3, 'pointer-events': 'none' })

and after closing child window to resume

$('body').css({ 'opacity': 1, 'pointer-events': 'auto' });

Now my question is when I click on Parent window, how can I focus on child?

Answer Source

There are roughly three parts to this:

  1. When you open the child window, put a full-page iframe on top of the parent window. This answer has an explanation and example (using jQuery; I note you're using jQuery in the question).

  2. Have clicks on that iframe call focus on the child window.

  3. On unload of the child window, remove the iframe.

Just in case that other answer disappeared for any reason, here's the example in it:


<input type='button' id='btnPopup' value='Click for Pop-Up'>
<p>This is text on the page</p>
<p>This is text on the page</p>
<p>This is text on the page</p>
<p>This is text on the page</p>
<p>This is text on the page</p>


jQuery(function($) {
  $('#btnPopup').click(function() {
    $("<iframe id='shim' src=''>").css({
      width: "100%",
      height: "100%",
      position: "absolute",
      left: "0px",
      top: "0px",
      zIndex: "100",
      backgroundColor: "#fff",
      opacity: "0.5"
    $("<div>Hi there, click me to dismiss</div>").css({
      zIndex: "101",
      border: "1px solid black",
      backgroundColor: "#ecc",
      position: "absolute",
      left: "100px",
      top: "100px"
      .click(function() {

( is just a blank page.)

Live Example - Again, this is just #1 of the above, you'll need to add #2 and #3.