0

How to set Popup child window center of parent window for different browsers

Please check here

Please check the below code. Tried below code for child popup center.

code var new_window;
function winOpen(){
width = window.innerWidth - 100; height = window.innerHeight - 120; var top = (screen.height - window.innerHeight) - 10; var left = 100 / 3;
new_window=window.open('https://www.google.com',"_blank","toolbar=0, help:no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=" + width + ", height=" + height + ",top=" + top + ",left=" + left + "");
}
code

user1124166
  • 1
  • 1
  • 1
  • 5
  • 3
    Does this answer your question? [How to center an element horizontally and vertically](https://stackoverflow.com/questions/19461521/how-to-center-an-element-horizontally-and-vertically) – D-Money Sep 30 '21 at 15:50
  • @D-Money - No, Thanks ! Please check - https://i.stack.imgur.com/Xknwb.png – user1124166 Sep 30 '21 at 15:59
  • Is the popup an element of the page, or a separate tab / window? If it is a separate tab / window, you do not have access to things happening outside the window as a normal webpage. – async await Sep 30 '21 at 16:55

1 Answers1

0

You can center elements inside the DOM in numerous ways, they are too many to list. However, usually it is done without JavaScript (your tag), but rather with CSS.

One way is by setting display:flex;, place-items:center and justify-content:center; on the parent;

Here is an example:

.parent {
  width: 150px;
  height: 150px;
  background: #08f;
  
  display: flex;
  justify-content: center;
  place-items: center;
}

.child {
  width: 95px;
  height: 95px;
  background: #0a0;
}
<div class="parent">
  <div class="child">Child</div>
</div>
Krokodil
  • 1,165
  • 5
  • 19