Home >Web Front-end >JS Tutorial >Summary of nine js methods to pop up dialog boxes_javascript skills
[1. The most basic js pop-up dialog window code]
This is the most basic js pop-up dialog box. In fact, the code is very simple:
Because this is a piece of javascripts code, they should be placed between the . are effective for some older browsers. In these old browsers, the code in the tag will not be displayed as text. Develop this good habit.
window.open ("page.html") is used to control the pop-up of a new window page.html. If page.html is not in the same path as the main window, the path should be written in front, the absolute path (http:// ) and relative paths (../) are available. You can use either single quotes or double quotes, just don't mix them.
This piece of code can be added anywhere in the HTML, between
[2. Add js pop-up dialog code for attribute settings]
Let’s talk about the settings of js pop-up dialog window properties. Just add a little more to the code above.
Let’s customize the appearance, size, and pop-up position of the window that pops up in this js pop-up dialog box to suit the specific conditions of the page.
end of js script
[3. Use functions to control js pop-up dialog windows]
The following is the code for a complete js pop-up dialog box.
A function openwin() is defined here, and the function content is to open a window. It serves no purpose until it is called.
How to call it?
Method 1: A window pops up when the browser reads the page;
Note: The "#" used is a virtual connection.
Method 4: Call with a button:
【4. js pop-up dialog box that pops up 2 windows at the same time】
Slightly change the source code:
Note: The names of the two js pop-up dialog windows (newwindows and newwindow2) should not be the same, or they should all be empty.
[5. Open the file 1.htm in the main window, and the small window page.html will pop up at the same time]
The following code is added to the main window
area:That’s it.
[6. Timing closing control of js pop-up dialog box window]
Next, let’s control the window of the js pop-up dialog box, and the effect will be better. If we add a small piece of code to the pop-up page (note that it is added to the HTML of page.html, not the main page, otherwise...), wouldn't it be cooler if it automatically closes after 10 seconds?
First, add the following code to the
area of the page.html file:【7. Add a close button in the js pop-up dialog window】
[8. The included js pop-up dialog window - two windows on one page]
The above examples all contain two windows, one is the main window and the other is a pop-up small window.
With the following example, you can complete the above effect in one page.
[9. Ultimate application--JS pop-up dialog window cookie control]
Recall that although the above pop-up window is cool, there is a little problem (you must not have noticed it if you are immersed in joy, right?) For example, if you put the above script in a page that needs to be passed frequently (such as the homepage) , then every time the page is refreshed, the window will automatically execute the js pop-up dialog code once. Isn't it very annoying? :-(Is there a solution? Yes! ;-) Follow me.
We use cookies to control it.
First, add the following code to the
area of the main page HTML: