分类:
2005-07-29 14:10:37
Now let's add some JavaScript...
This link will open in a new window created by HTML and JavaScript.
Here the code is a bit more complicated...
"blank","toolbar=no,width=250,height=250")>new window
Although the text "new window" seems to be a hyperlink it isn't. It just looks and behaves like one. The text is enclosed not by the usual tags but by tags. These and the similar I wanted it to look like a hyperlink because it was going to behave like a hyperlink. I couldn't actually use a hyperlink because of what was going to happen next... Atttached to the text is an onClick event that triggers one of the standard JavaScript functions, window.open. This function can have three parameters applied to it, and these control exactly what happens when the new window opens: window.open("URL","name","attributes") This is where you get to be creative with your windows. Here's what the various bits mean... "URL": This is the address of the page that you want to open in the new window. "name": This is a name of your choice. The purpose of providing a name is that you can then refer to it elsewhere. You might want a subsequent hyperlink to open in the same window you just created, replacing the earlier page. Your user doesn't have to shut down each window when they have finished with it. They just switch back when its contents change. You can leave out the name if you like, just type empty quotes: "". "attributes": These are a set of instructions that tell the browser how to display the window. In the above example I have used toolbar=no which, when used alone tells the browser to open a basic window without toolbars, scroll bars, status bars etc. I have also specified an exact size by including width=250 and height=250, the numbers referring to pixels. Value = yes or no, 1 or 0. Value = yes or no, 1 or 0. Value = yes or no, 1 or 0. Value = yes or no, 1 or 0. Value = yes or no, 1 or 0. Value = yes or no, 1 or 0. Value = number Value = number Value = number Value = number Value = yes or no, 1 or 0. Value = yes or no, 1 or 0. You will find that when, for example, you specify toolbar=no that other objects (location, menubar, scrollbars etc.) get switched off too. If you want to see any of them in your new window you will have to ask for them specifically. :
menubar Specifies whether or not to display a menu bar at the top of the window. toolbar Specifies whether or not to display the main toolbar (with the back, forward, stop etc. buttons). location Specifies whether or not to display the location bar (the Address Bar in Internet Explorer) - where URLs are typed and displayed. directories Specifies whether or not to display any additional toolbar (e.g the Links Bar in Internet Explorer). status Specifies whether or not to display the status bar at the foot of the window. scrollbars Specifies whether or not to display the horizontal and vertical scrollbars that normally appear when the page content is larger than the screen. height Specifies the height of the window in pixels. width Specifies the width of the window in pixels. left Specifies the distance in pixels of the new window from the left edge of the screen. (This applies to Internet Explorer. For Netscape Navigator use screenX). top Specifies the distance in pixels of the new window from the top edge of the screen. (This applies to Internet Explorer. For Netscape Navigator use screenY). resizable When enabled, allows the user to manually resize the window by dragging its edges or corners. fullscreen When enabled causes the window to open in full-screen mode (Internet Explorer only.)