Pages

Thursday, August 18, 2011

Center a new popup window even on dualscreen with javascript

function PopupCenter(url, title, w, h) {
    // Fixes dual-screen position                         Most browsers      Firefox
    var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
    var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
            
    width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
    height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
            
    var left = ((width / 2) - (w / 2)) + dualScreenLeft;
    var top = ((height / 2) - (h / 2)) + dualScreenTop;
    var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

    // Puts focus on the newWindow
    if (window.focus) {
        newWindow.focus();
    }
}
Usage example:
PopupCenter('http://www.xtf.dk','xtf','900','500');
UPDATE: It will also work on minimized windows

45 comments:

  1. Just wanted to say thanks for this! It works great!

    ReplyDelete
  2. ...and thanks from me too! It works well and centres a pop-up within the 'parent' page - unless the parent is smaller than the pop-up! Can I suggest that the pop-up is centred on the center of the parent?

    ReplyDelete
  3. Thank you for this, it works great !!! It's exactly what I want !!!

    ReplyDelete
  4. I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. Search Bar Firefox 57 Quantum addon

    ReplyDelete
  5. This doesn't work with, old legacy, applications that have nexted framesets or iframes.

    You must add .top to the window calls. IE: window.top.screenLeft

    ReplyDelete
  6. Nine years later, this is as useful as can be. Thanks a lot.

    ReplyDelete
  7. Go through the partner's portfolio and reviews. Also consider scheduling an appointment with the partner so that you can learn more about him/her. Salesforce training in Chennai

    ReplyDelete
  8. A security door is a great way to add an extra element of protection for your home and family. Because many burglars prefer to use the front door when planning and executing a robbery, it is imperative that great care is taken when looking to create a barrier of security. It surprises many that there are several various screen door options that can add an aesthetic appeal to the home while simultaneously creating an added layer of protection. Security doors

    ReplyDelete
  9. Thanks for Sharing This Article.It is very so much valuable content. . AWS course in Chennai

    ReplyDelete
  10. If you are a owner of a house then you should visit Pelican Paint. They are the painting company that is providing the best painters at a low cost. Its hard to get an expert. So don't waste your time. If you need one then please visit the site.

    ReplyDelete
  11. หาคุณกำลังหาเกมส์ออนไลน์ที่สามารถสร้างรายได้ให้กับคุณ เรามีเกมส์แนะนำ เกมยิงปลา รูปแบบใหม่เล่นง่ายบนมือถือ คาสิโนออนไลน์ บนคอม เล่นได้ทุกอุปกรณ์รองรับทุกเครื่องมือ มีให้เลือกเล่นหลายเกมส์ เล่นได้ทั่วโลกเพราะนี้คือเกมส์ออนไลน์แบบใหม่ เกมยิงปลา

    ReplyDelete
  12. Thank you for sharing this information. Looking for such more content in the future.
    tensorflow course
    tensorflow online training
    tableau training

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. If you are looking for an honest site, UFA, UEFA Bet casino site. Which may be played as an extensive answer, able to answer Quality and Performance It's best to have a great deal of the issues. It can certainly be a thing quite hitting & intriguing. Excellently, the items that UFABET football betting is not even with the experience of quality. And availability that are able to see effects It's a model that is rather clear and diverse. Filled with operation of making money Attractiveness With the best possibilities it's really nothing You can find probabilities and opportunities for earning money. Quality and pretty varied For those who have arrive at make use of the program excellently.บาคาร่า
    ufa
    ufabet
    แทงบอล
    แทงบอล
    แทงบอล

    ReplyDelete
  15. อย่างไรก็ตามในการเล่นเกมส์คาสิโนออนไลน์หรือการเดิมพันออนไลน์ชนิดต่างๆคุณจะต้องให้ความสำคัญในเรื่องของการเลือกเว็บคาสิโนออนไลน์เลือกเว็บเดิมพันออนไลน์ที่คุณจะใช้บริการให้ดีคุณจำเป็
    สล็อต
    นที่จะต้องศึกษาและหาข้อมูลเกี่ยวกับเว็บก่อนที่คุณจะตัดสินใจใช้บริการเพื่อความปลอดภัยในการใช้บริการของคุณและเพื่อประโยชน์ในการใช้บริการเว็บที่คุณจะต้องใช้บริการไปอีกนานถ้าคุณใช้บริการเว็บที่ให้บริการที่ดีคุณก็จะมีความสะดวกสบายในการใช้บริการเว็บคาสิโนออนไลน์หรือเว็บเดิมพันออนไลน์ต่างๆ

    ReplyDelete
  16. youtube abone satın al
    cami avizesi
    cami avizeleri
    avize cami
    no deposit bonus forex 2021
    takipçi satın al
    takipçi satın al
    takipçi satın al
    takipcialdim.com/tiktok-takipci-satin-al/
    instagram beğeni satın al
    instagram beğeni satın al
    btcturk
    tiktok izlenme satın al
    sms onay
    youtube izlenme satın al
    no deposit bonus forex 2021
    tiktok jeton hilesi
    tiktok beğeni satın al
    binance
    takipçi satın al
    uc satın al
    sms onay
    sms onay
    tiktok takipçi satın al
    tiktok beğeni satın al
    twitter takipçi satın al
    trend topic satın al
    youtube abone satın al
    instagram beğeni satın al
    tiktok beğeni satın al
    twitter takipçi satın al
    trend topic satın al
    youtube abone satın al
    takipcialdim.com/instagram-begeni-satin-al/
    perde modelleri
    instagram takipçi satın al
    instagram takipçi satın al
    takipçi satın al

    ReplyDelete
  17. Du kan lave video om dette popup -vindue og sende det på tiktok. Hvis du vil gøre video populær, skal du Køb Tiktok Likes for den

    ReplyDelete
  18. Online shopping is so convenient, but buying larger ticket items can sometimes be daunting. Here are some tips to make buying furniture online go smoothly. exterior doors

    ReplyDelete
  19. This was an extremely wonderful post. Thanks for providing this info. Blade Runner 2049 Coat

    ReplyDelete
  20. Our team are trained in dealing with the specific potential threats in these circumstances. For individuals requiring protection, we can conduct our security chauffeur
    services with minimal intrusion to your daily activities so you can have the peace of mind of feeling protected without having to completely change your routine or disrupt your life.

    ReplyDelete
  21. yet pick a decent quality window in any case. You would prefer not to pick a window that main looks great however will not get a good deal on service bills. silk bed sheets

    ReplyDelete
  22. Thanks for the best blog. it was very useful for me.keep sharing such ideas in the future as well. guardians of the galaxy star lord game jacket

    ReplyDelete
  23. I love to recommend you Where can crawl Exciting Products latest Jackets, Coats and Vests Click Here Biker Boyz Jacket

    ReplyDelete
  24. Hey, this day is too much good for me, since this time I am reading this enormous informative article here at my home. Thanks a lot for massive hard work. garage doors blog

    ReplyDelete
  25. For all the momentum equipment in presence, drivers have as of now been distributed on the off chance that they will be. https://www.westseattlewindowcleaner.com/why-quality-window-cleaning-bellevue-matters

    ReplyDelete
  26. I was very impressed by this post, this site has always been pleasant news Thank you very much for such an interesting post, and I meet them more often then I visited this site. Good For Health Bad For Education Jacket

    ReplyDelete
  27. Excellent article. Very interesting to read. I really love to read such a nice article. Thanks! keep rocking. glass repair near me

    ReplyDelete
  28. We should expect, for instance, as far as possible for the window tint of a vehicle is 30% and the vehicles glass has a VLT worth of 75%.
    Expert Window Tinting

    ReplyDelete