While the browser always gives new windows the focus when they're first created, it doesn't refocus when you send another page to a window that's already open. If it is, we set the browser's focus on the new window, so that as soon as it is affected it is at the front of the display. Firstly, in our function at the start of this page, we executed the following code once the window had been created:įirst we check whether the focus() method is supported - this is vital to stop JavaScript errors. Two vital little tricks can make your popups infinitely more usable. Top=100,resizable=yes,scrollbars=yes,toolbar=yes,status=yes') So, a fully kitted-out new window might look more like this: screenX & screenY Old Netscape attributes for defining the window's position on the page. If the main window is closed, the popup closes with it. dependent Netscape 4-only attribute which makes the popup dependent on the status of the main window. fullscreen Internet Explorer-only Boolean attribute which may open the window in fullscreen. directories Specifies whether the directories toolbar is shown (Links toolbar in IE). For security reasons, Mozilla-based browsers always show the status bar. status Specifies whether the new window can have a status bar. location Specifies whether the location toolbar (address bar) is shown. menubar Specifies whether the main toolbar (File, Edit. If there are links to follow in your new page, set this to yes. toolbar Specifies whether the basic back/forward toolbar should be visible. If your content may be longer then the dimensions you've specified, make sure this is set to yes. scrollbars Another Boolean value, this adds scrollbars to the new window. resizable Set to true or false, this may allow the user to resize the window. top Partner to left, this pushes the window off the top of the screen. left Supported by version 4 browsers and above, this sets how far removed the window appears from the left of the screen. Again, you'll have no joy with percentages. height Defines the height of the window in pixels. Whichever you choose to use, all of your options go into the same quoted string, with commas between the values, and no spaces are allowed between them. ![]() When you define any of them, the remaining Boolean values (which can be true/false or yes/no or 1/0) are all set to false/no/0. You have a number of options for the third argument. The name we specify will be used to open further pages into this new window. Some browsers prohibit the opening of pages on another server for security reasons, so test your script. The url we're using is passed to the function when we call it, so that this function can be used for any number of different popups (though the height/width and other options will always be the same unless you modify the function to take more arguments). This method then takes three arguments: the address of the new page, the name of the window, and a third argument which can hold some, few, or less optional attributes of the window, such as the height and width which I've defined in this case. ![]() We load the new window (created with the window.open() method) into a variable. The HTML for that link simply called the function with the URL of the page we want to pop up as an argument. This will open the specified url in a new, downsized window, the dimensions of which are set down in the function. We're simply defining a new JavaScript function, which we can pass different URLs to each time. To get a rudimentary page to pop up off your main page on command from a link, you'll need the following JavaScript code and JavaScript link: However, if you want more control over this new window, you will need to use some JavaScript code. ![]() This will open the new page in a new window, and is perfect for most people’s needs. Opening new windows is easy enough in plain old HTML, using the target attribute on your links, like so:
0 Comments
Leave a Reply. |