how to make popup windows always on top?

大城市里の小女人 提交于 2019-12-01 22:02:00

问题


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.


回答1:


myWindow.focus()

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




回答2:


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

<body onblur="self.focus();"> 



回答3:


Im sure you cannot control the order of the window. Instead of a popup (which is often and usually blocked by browsers) why not investigate using a lightbox javascript plugin. They are usually free, stylish and work well.




回答4:


Just set it from the modal css. The z-index is normally set to 1. Just change it to 9999. That is the purpose of the z-index, to set the popup top level.

If not using bootstrap popup, then you need to use css to set it. Browsers are not guaranteed to place nice with .focus() on a window.



来源:https://stackoverflow.com/questions/5576596/how-to-make-popup-windows-always-on-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!