

In JavaScript, we can use window.parent for accessing parent window elements/functions. Sometimes, we may need to pass values from child modal window to parent window while using " ShowURL" function of modal window. X.moveTo(Math.round((scW-oW)/2),( ' You can not drag this window', 200, 400, ' User Information') Passing Values From Modal Popup Child Window To Parent Window

Var scH = screen.availHeight ? screen.availHeight : screen.height Var scW = screen.availWidth ? screen.availWidth : screen.width Simply replace this: x.resizeTo( oW + ( ( oW + 200 ) - myW ), oH + ( (oH + 200 ) - myH ) ) Therefore, all we have to do is to reposition the centre of the popup in the centre of theĪvailable screen space. We can also measure the size of the screen (I like to find theĪvailable size just in case). Therefore we know how big the outside of the window is. Since the last time we resize the window, we know what size we are resizing it to, and But what about centering the popup on the screen (you may notice that I did that too)? Hopefully, the Chrome development team will at some point fix the bug. This is a bug in Chrome, and I do not intend to work around it.

These experiments made it fail to handle resizing correctly, and as a result, it does not work correctly with this script. (Thanks to Peter Schroeder for reporting this bug.)Ī special note for Chrome: Google's Chrome made several experiments with the UI, and one of the experiments was with the way it handles popups. Adding a couple of extra lines of text into the popup above wouldĪvoid this problem. Non-existent status bar that appeared during the resize. Is not enough text in the popup window (as shown in the example above), they may leave a gap underneath the text, caused by the

Test it here: Open a popup containing text.Ī special note for Firefox: Some Firefox releases have trouble deciding when to show the status bar. The HTML contains: Open a popup containing text.
#Javascript popup window examples how to
Writing with script page for how to dynamically write contents. See my customisable window page for how to open windows, as well as my Opening a window and dynamically writing its contents
#Javascript popup window examples license
To see the script license and check details like browser compatibility, use the links on the navigation panel at the top of this page. Or for a popup: var foo = window.open('somepage.html','_blank','someOptions') įoo.resizeTo(screen.availWidth,screen.availHeight) Note, if you just want to resize and reposition the current window so it perfectly matches your screen, you want this: window.moveTo(0,0) This technique is perfect for shoppingĬart product lists or photo galleries, where clicking a link opens up a popup containing just a picture. Technique could also be used to make a window resize to fit its contents, even if it has not been dynamically created.ĭon't abuse popups, you will end up loosing visitors who become annoyed by them. This describes how to open a window, dynamically write its contents, then resize it to exactly fit those contents.
