how to make popup windows always on top?

21,911

Solution 1

myWindow.focus()

Many modern browsers prevent this from working, but it's the only way.

Solution 2

use following javascript code in the page you are opening in popup

<body onblur="self.focus();"> 
Share:
21,911
sams5817
Author by

sams5817

Updated on July 09, 2022

Comments

  • sams5817
    sams5817 almost 2 years

    I want to have a javascript/jQuery popup window (child page) that is always in front of the parent page, something like facebook's current picture viewing feature.

    it would be closed by the user clicking on the close button.

    I have tried as below:

    mywindow  = window.open ("DownloadForm.aspx", "mywindow","location=1,status=1,scrollbars=1, width=350,height=150");
    mywindow.moveTo(350, 350);
    

    this code successfully opened a child page in front of the parent page, but there is jQuery code ( $(#test).click() ) on the parent page which causes the parent page to always be in front.

    I tried putting the window.open() code after $(#test).click(), but it didn't solve the problem.

    The $(#test).click() is necessary, therefore I need to have a workaround.

    I appreciate any help, thank you in advance.

  • Amr Elgarhy
    Amr Elgarhy about 13 years
    and this is what facebook is doing
  • Craig White
    Craig White about 13 years
    Facebook uses there own library of Javascript API and modal boxes. Simply Google 'lightbox javascript' or 'javascript modal dialog' and you will find many downloadable scripts. Choose one taht fits waht you need.
  • Amr Elgarhy
    Amr Elgarhy about 13 years
    Yes, I mean Facebook is not using a popup window there a using a popup layer in the same page.
  • Craig White
    Craig White about 13 years
    Yes, facebook just has absolute positioned div's with a higher z-index (its a css style)