Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

window open center

const popupCenter = ({url, title, w, h}) => {
    // Fixes dual-screen position                             Most browsers      Firefox
    const dualScreenLeft = window.screenLeft !==  undefined ? window.screenLeft : window.screenX;
    const dualScreenTop = window.screenTop !==  undefined   ? window.screenTop  : window.screenY;

    const width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
    const height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;

    const systemZoom = width / window.screen.availWidth;
    const left = (width - w) / 2 / systemZoom + dualScreenLeft
    const top = (height - h) / 2 / systemZoom + dualScreenTop
    const newWindow = window.open(url, title, 
      `
      scrollbars=yes,
      width=${w / systemZoom}, 
      height=${h / systemZoom}, 
      top=${top}, 
      left=${left}
      `
    )

    if (window.focus) newWindow.focus();
}


popupCenter({url: 'http://www.xtf.dk', title: 'xtf', w: 900, h: 500});  
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to skip the execution or for loop using continue js 
Javascript :: run node script pupeeter when button from form clicked 
Javascript :: create multidimensional array javascript for loop 
Javascript :: find method javascript 
Javascript :: change the color of toast toastr js 
Javascript :: greater than x but less than y javascript 
Javascript :: how to select an adjacent element javascript 
Javascript :: javascript for of loop 
Javascript :: node localstorage 
Javascript :: next js css background image 
Javascript :: react-data-table-component cell action 
Javascript :: find object in array 
Javascript :: luxon plus 
Javascript :: how to make a circle in p5js 
Javascript :: how to get MathJax 
Javascript :: json-server localhost 
Javascript :: how to write query string js 
Javascript :: ${ js 
Javascript :: javascript concat 
Javascript :: js number padding to number of characters 
Javascript :: react-native make android apk 
Javascript :: js number round to each 15 
Javascript :: round number javascript 
Javascript :: update object in array state react 
Javascript :: javascript compare number 
Javascript :: react native force vertical 
Javascript :: javascript bool 
Javascript :: events onclick 
Javascript :: double click on element using javascript 
Javascript :: javascript function add two numbers 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =