Friends who frequently access the Internet may have visited such websites. when they enter the home page, a window will pop up immediately, or a connection or button will pop up, this window usually displays some precautions, copyright information, warnings, visits, and other information that the author wants to remind him. In fact, it is very easy to make such a page. You only need to add several Javascript codes to the HTML of the page. Next, I will take you through the analysis of its mysteries.
[1. The most basic pop-up window Code]
In fact, the code is very simple:
<Script language = "javascript"> "〉
<〈! --
Window. open ('page.html ')
--> --〉
</SCRIPT> 〉
Because this is a piece of javascripts code, they should be placed between <script language = "javascript">. <〈! -- And --> are used for some earlier browsers. The code in the labels is not displayed as text in these old browsers. This is a good habit.
Window. open ('page.html ') is used to control the pop-up window page.html. If page.html is not in the same path as the main window, the path, absolute path (http: //), and relative path (../) should be specified before.
You can use single quotes and double quotes, but do not mix them.
This piece of code can be added to any location of HTML. It can be between head and head, or between body and body. The earlier the code is executed, especially if the Page code is long and you want to bring the page up early, try to move it forward. Alternatively, the earlier the page is executed, especially the long Page code. If you want the page to pop up early, try to move it forward.
[2. After setting, the pop-up window is displayed]
Let's talk about the settings in the pop-up window. You just need to add something to the code above. We will customize the appearance, size, and position of the pop-up window to adapt to the specific situation of the page.
<Script language = "javascript"> "〉
<〈! --
Window. open ('page.html ', 'newwindow', 'height = 100, width = 400, top = 0, left = 0, toolbar = no, menubar = no, scrollbars = no, resizable = no, location = no, status = no ')
// Write a row
--> --〉
</SCRIPT> 〉
Parameter description:
<Script language = "javascript"> the js SCRIPT starts;
Window. open command to pop up a new window;
'Page.html 'name of the pop-up window;
'Newwindow' indicates the name of the pop-up window (not the file name). It is optional and can be replaced by null;
Height = 100 window height;
Width = 400 window width;
Top = the pixel value between the 0 window and the top of the screen;
Left = 0 the pixel value between the window and the left of the screen;
Toolbar = no indicates whether to display the toolbar. yes indicates display;
Menubar and scrollbars indicate the menu bar and scroll bar.
Resizable = no: whether to change the window size. yes: yes;
Location = no indicates whether the address bar is displayed. yes indicates yes;
Status = no whether to display the information in the status bar (usually the file has been opened), yes is allowed;
</SCRIPT> end of js SCRIPT