JS pop-up window Code Daquan (detailed finishing) _javascript skills

Source: Internet
Author: User
How to use the Web page pop-up various forms of windows, I think most of us are aware of some, but the kind of a variety of pop-up window is how to get out, we have to learn today:
1. Bounce a full-screen window
Copy Code code as follows:

<body http://www.jb51.net ', ' cloud-dwelling community ', ' fullscreen '); >;
<b>www.jb51.net</b>
</body>

2. Restart a F11 window
Copy Code code as follows:

<body ' http://www.jb51.net ', ' cloud-dwelling community ', ' Channelmode '; >;
<b>www.jb51.net</b>
</body>

3. Bounce A window with the Favorites link toolbar
Copy Code code as follows:

<body www.wangye8.com ', ' cloud-dwelling community ', ' width=400,height=300,directories '); >
<b>www.wangye8.com</b>
</body>

4. Web Page dialog Box
Copy Code code as follows:

<script language= "JavaScript" >
<!--
ShowModalDialog (' Http://www.jb51.net, ' cloud-dwelling community ', ' dialogwidth:400px;dialogheight:300px;
Dialogleft:200px;dialogtop:150px;center:yes;help:yes;resizable:yes;status:yes ')
-->
</SCRIPT>
<b>www.wangye8.com</b>
</body>
<script language= "JavaScript" >
<!--
showModelessDialog (' Http://www.jb51.net, ' cloud-dwelling community ', ' dialogwidth:400px;dialogheight:300px;
Dialogleft:200px;dialogtop:150px;center:yes;help:yes;resizable:yes;status:yes ')
-->
</SCRIPT>
<b>http://www.wangye8.com</b>
</body>

ShowModalDialog () or showModelessDialog () to invoke the Web Page dialog, the difference between ShowModalDialog () and showModelessDialog () is ShowModalDialog ( Open window (short mode window), placed on the parent window, must be closed to access the parent window (recommended as little as possible, so as not to be annoying); showModelessDialog ()
Dialogheight:iheight sets the height of the dialog box window.
Dialogwidth:iwidth sets the width of the dialog box window.
Dialogleft:ixpos sets the left position of the dialog window relative to the upper-right corner of the desktop.
Dialogtop:iypos sets the top position of the dialog window relative to the upper-left corner of the desktop.
Center: {yes | no | 1 | 0} Specifies whether the dialog box is centered on the desktop, and the default value is yes.
Help: {yes | no | 1 | 0} Specifies whether the context-sensitive aid icon is displayed in the dialog box window. The default value is yes.
Resizable: {yes | no | 1 | 0} Specifies whether the dialog box window is variable in size. The default value is "no".
Status: {yes | no | 1 | 0} Specifies whether the dialog box window displays the status bar. For modeless dialog windows, the default value is Yes, and for modal dialog windows, the default is "no".

5, other pop-up window code
Frequent Internet friends may have been to such websites, a page immediately will pop up a window, or press a link or button pop-up, usually in this window will show some attention, copyright information, warning, Welcome to patronize and so on, or the author wants to special tips information. In fact, it is very easy to make such a page, as long as the HTML page to add a few pieces of Java script code can be implemented. Below I will take you to dissect its mystery.

"Most basic pop-up window code"
In fact, the code is very simple:
Copy Code code as follows:

<script language= "java SCRIPT" >
<!--
window.open (' page.html ')
-->
</SCRIPT>

Because this is a piece of Java script code, they should be placed between <script LANGUAGE = "java Script" > tags and </script>. <!--and--> are useful for some versions of browsers that do not support Java script in these old browsers and do not display the code as text in the label.
window.open (' page.html ') is used to control the pop-up of the new window page.html, if page.html is not in the same path as the main window, before the path, absolute path (http://) and relative path (...) should be specified. /) are available.
Both single and double quotes are OK, just don't mix.
This piece of code can be added to the HTML anywhere, add to the
"After a set pop-up window"
Let's say the settings for pop-up window appearance. Just add something to the code above.
Let's customize the appearance, size, and popup position of this pop-up window to fit the page's specifics.
Copy Code code as follows:

<script language= "Java script:>
<!--
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 line
-->
</SCRIPT>

parameter Explanation
<script language= "java Script" > JS scripts started;
window.open the command to eject a new window;
page.html the filename of the new window pop-up;
NewWindow pop-up window name (not filename), can be replaced by empty ″;
height=100 window height;
The pixel value of the Top=0 window from the top of the screen;
The pixel value of the left=0 window from the left side of the screen;
Toolbar=no whether the toolbar is displayed, yes for display;
Menubar,scrollbars represents the menu bar and scroll bar;
Resizable=no whether to allow changes to the window size, yes to allow;
Location=no whether the address bar is displayed, yes is allowed;
Status=no whether the information in the status bar is displayed (usually the file is open), yes to allow;
</SCRIPT> JS script end.

"Control pop-up window with function"
The following is a complete code.
Copy Code code as follows:

<script language= "java Script" >
<!--
function Openwin () {
window.open ("page.html", "NewWindow", "Height=100,width=400,toolbar=no,menubar=no,scrollbars=no,resizable=no,
Location=no,status=no ";)
Write a line
}
-->
</script>
<body >
... Any page content ...
</body>

A function Openwin () is defined here, and the function content is to open a window. There is no use before calling it. How to call it?
Method One: <body > Browser pop-up window when reading the page;
Method Two: <body > Browser pop-up window when leaving the page;
Method Three: Call with a connection: <a href= "#" > Open a Window </a>
Note: The "#" used is a virtual connection.
Method Four: Call with a button: <input type= "button" value= "open Window" >

"The main window opens the file 1.htm, while the small window pops up page.html"
Add the following code to the main window
Copy Code code as follows:

<script language= "java Script" >
<!--
function Openwin () {
window.open ("page.html", "", "width=200,height=200";)
}
-->
</script>

Add <body>: <a href= "1.htm" >open</a> can.

"timed off control of the pop-up window"
Next we have some control of the pop-up window, the effect is better. If we add a small piece of code to the pop-up page (note is added to the page.html HTML, not the main page, otherwise ...) So that it automatically shuts down in 10 seconds, is it cooler?
First, add the following code to the
Copy Code code as follows:

<script language= "java Script" >
function Closeit () {
SetTimeout ("Self.close ()", 10000)//MS
}
</script>

Then, then use <body > This sentence to replace page.html in the middle of some <BODY> this sentence on it. (Don't forget to write this sentence!) The function of this sentence is to call the code that closes the window, and then close the window itself after 10 seconds. )

"Add a close button to the pop-up window"
Copy Code code as follows:

<form>
<input type= ' BUTTON ' value= ' closed '
</form>

Oh, now more perfect!
"Contains pop-up windows--one page two windows"
The example above contains two windows, one is the main window and the other is a pop-up window.
With the example below, you can do the above in one page.
Copy Code code as follows:

<script language= "java SCRIPT" >
function Openwin ()
{
Openwindow=window.open ("", "Newwin", "height=250,width=250,toolbar=no,scrollbars=" +scroll+ ", menubar=no";);
Write a line
OpenWindow.document.write ("<TITLE> example </TITLE>";)
OpenWindow.document.write ("<body bgcolor= #FFFFFF >";)
OpenWindow.document.write ("<H1>Hello!OpenWindow.document.write ("New window opened!";)
OpenWindow.document.write ("</body >";)
OpenWindow.document.write ("</HTML>";)
OpenWindow.document.close ()
}
</script>
<body>
<a href= "#" > Open a Window </a>
<input type= "button" value= "open Window" >
</body>

Look at the code inside OpenWindow.document.write () is not standard HTML? Just write more lines in the format. Be sure to note that one or fewer tabs will have an error. Remember to end with OpenWindow.document.close ().

"Ultimate Application-Pop-up window cookie control"
Recall that the above pop-up window is cool, but there is a little trouble (you are immersed in joy, must not find it?) For example, you put the above script in a page that needs to go through frequently (for example, the first page), then each refresh this page, the window will pop up once, is not very annoying? Is there any way to solve it? yes! Follow me. We can use cookies to control it.
First, add the following code to the <HEAD> area of the homepage HTML:
Copy Code code as follows:

<script>
function Openpopup () {
window.open ("hello.htm", "", "width=300,height=300")//modify pop-up windows yourself
}
function Get_cookie (Name) {
var search = Name + "="
var returnvalue = "";
if (Documents.cookie.length > 0) {
offset = documents.cookie.indexOf (search)
if (offset!=-1) {//if cookie exists
Offset + = Search.length
Set index of beginning of value
End = Documents.cookie.indexOf (";", offset);
Set index of end of cookie value
if (end = = 1)
end = Documents.cookie.length;
Returnvalue=unescape (documents.cookie.substring (offset, end))
}
}
Return returnvalue;
}
function Loadpopup () {
if (Get_cookie (' popped ') = = ") {
Openpopup ()
Documents.cookie= "Popped=yes"
}
}
</script>

Type the following code into the body area:
<body >//pop when leave page
Or:
<body >//pop When enter page
You can try to refresh the page or re-enter the page, and the window will never pop again. The real pop-only-once!.
Written here, the pop-up window of the production and application skills are basically finished, I hope to be making a friend of the Web site to help me very relieved.
Note that the capitalization in the JS script is best kept consistent.
There are no pop-up windows for menus, toolbars, and address bars:
Copy Code code as follows:

<script language= "java Script" >
<!--
var gt = unescape ('%3e ');
var popup = null;
var over = "Launch pop-up Navigator";
Popup = window.open (', ' Popupnav ', ' Width=500,height=500,resizable=0,scrollbars=auto '); width=500,height=500 for window length and width
if (popup!= null) {
if (Popup.opener = = null) {
Popup.opener = self; }
Popup.location.href = ' filename to open ';
}
-->
</script>

Method Two: Cookies Application: Control pop-up window when we set a pop pop-up window in a page, every time we browse the page again, Pop window will automatically bounce out, causing unnecessary trouble. So how do we solve this problem? Here's a simple example of how you can use cookies to get pop-up windows to pop up only the first time you browse the page, and then stop annoying!
<script> function Openpopwindow () {window.open ("hello.htm", "", "width=200,height=200"//Modify pop-up window} function get_ Cookie (name) {var search = name + "="; var returnvalue = ""; if (Documents.cookie.length > 0) {offset = documents.cookie.indexOf (search); if (offset!=-1) {//If there was previously a cookie record off Set + + Search.length; Sets the starting position of the cookie end = Documents.cookie.indexOf (";", offset); Sets the end position of the cookie if (ending = = 1) ends = Documents.cookie.length; Returnvalue=unescape (documents.cookie.substring (offset, End)}} return returnvalue; function Loadpopup () {if (Get_cookie (' popped ') = = ') {Openpopwindow (); documents.cookie= "Popped=yes";}} </script& Gt
Type the code above into the body area: <body >//Popup when leaving the page
Or: <body >//Popup when opening the page

"This article copyright belongs to the author and the Osso net jointly owns, if needs to reprint, please indicate the author and the origin"
Bounce window effect when leaving page:
Effect: When someone closes this page, a window pops up and you can write some blessings.
Core code:
Copy Code code as follows:

<script language= "JavaScript" >
<!--Begin function leave () {
window.open
(' 1.htm ', ", ' toolbar=no,menubar=no,location=no,height=225,width=235 ');
Break
}
End-->
</script>

How to use the Web page pop-up various forms of windows, I think most of us are aware of some, but the kind of a variety of pop-up window is how to get out, we have to learn today:
1. Bounce a full-screen window
Copy Code code as follows:

<body http://www.jb51.net ', ' cloud-dwelling community ', ' fullscreen '); >;
<b>www.jb51.net</b>
</body>

2. Restart a F11 window
Copy Code code as follows:

<body ' http://www.jb51.net ', ' cloud-dwelling community ', ' Channelmode '; >;
<b>www.jb51.net</b>
</body>

3. Bounce a window with the Favorites Link toolbar
Copy Code code as follows:

<body www.wangye8.com ', ' cloud-dwelling community ', ' width=400,height=300,directories '); >
<b>www.wangye8.com</b>
</body>

4. Web Page dialog box
Copy Code code as follows:

<script language= "JavaScript" >
<!--
ShowModalDialog (' Http://www.jb51.net, ' cloud-dwelling community ', ' dialogwidth:400px;dialogheight:300px;
Dialogleft:200px;dialogtop:150px;center:yes;help:yes;resizable:yes;status:yes ')
-->
</SCRIPT>
<b>www.wangye8.com</b>
</body>
<script language= "JavaScript" >
<!--
showModelessDialog (' Http://www.jb51.net, ' cloud-dwelling community ', ' dialogwidth:400px;dialogheight:300px;
Dialogleft:200px;dialogtop:150px;center:yes;help:yes;resizable:yes;status:yes ')
-->
</SCRIPT>
<b>http://www.wangye8.com</b>
</body>

ShowModalDialog () or showModelessDialog () to invoke the Web Page dialog, the difference between ShowModalDialog () and showModelessDialog () is ShowModalDialog ( Open window (short mode window), placed on the parent window, must be closed to access the parent window (recommended as little as possible, so as not to be annoying); showModelessDialog ()
Dialogheight:iheight sets the height of the dialog box window.
Dialogwidth:iwidth sets the width of the dialog box window.
Dialogleft:ixpos sets the left position of the dialog window relative to the upper-right corner of the desktop.
Dialogtop:iypos sets the top position of the dialog window relative to the upper-left corner of the desktop.
Center: {yes | no | 1 | 0} Specifies whether the dialog box is centered on the desktop, and the default value is yes.
Help: {yes | no | 1 | 0} Specifies whether the context-sensitive aid icon is displayed in the dialog box window. The default value is yes.
Resizable: {yes | no | 1 | 0} Specifies whether the dialog box window is variable in size. The default value is "no".
Status: {yes | no | 1 | 0} Specifies whether the dialog box window displays the status bar. For modeless dialog windows, the default value is Yes, and for modal dialog windows, the default is "no".
5, other pop-up window code
Frequent Internet friends may have been to such websites, a page immediately will pop up a window, or press a link or button pop-up, usually in this window will show some attention, copyright information, warning, Welcome to patronize and so on, or the author wants to special tips information. In fact, it is very easy to make such a page, as long as the HTML page to add a few pieces of Java script code can be implemented. Below I will take you to dissect its mystery.

"Most basic pop-up window code"
In fact, the code is very simple:
Copy Code code as follows:

<script language= "java SCRIPT" >
<!--
window.open (' page.html ')
-->
</SCRIPT>

Because this is a piece of Java script code, they should be placed between <script LANGUAGE = "java Script" > tags and </script>. <!--and--> are useful for some versions of browsers that do not support Java script in these old browsers and do not display the code as text in the label.
window.open (' page.html ') is used to control the pop-up of the new window page.html, if page.html is not in the same path as the main window, before the path, absolute path (http://) and relative path (...) should be specified. /) are available.
Both single and double quotes are OK, just don't mix.
This piece of code can be added to the HTML anywhere, add to the
"After a set pop-up window"
Let's say the settings for pop-up window appearance. Just add something to the code above.
Let's customize the appearance, size, and popup position of this pop-up window to fit the page's specifics.
Copy Code code as follows:

<script language= "Java script:>
<!--
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 line
-->
</SCRIPT>

Parameter explanation:
<script language= "java Script" > JS scripts started;
window.open the command to eject a new window;
page.html the filename of the new window pop-up;
NewWindow pop-up window name (not filename), can be replaced by empty ″;
height=100 window height;
The pixel value of the Top=0 window from the top of the screen;
The pixel value of the left=0 window from the left side of the screen;
Toolbar=no whether the toolbar is displayed, yes for display;
Menubar,scrollbars represents the menu bar and scroll bar;
Resizable=no whether to allow changes to the window size, yes to allow;
Location=no whether the address bar is displayed, yes is allowed;
Status=no whether the information in the status bar is displayed (usually the file is open), yes to allow;
</SCRIPT> JS script end.

"Control pop-up window with function"
The following is a complete code.
Copy Code code as follows:

<script language= "java Script" >
<!--
function Openwin () {
window.open ("page.html", "NewWindow", "Height=100,width=400,toolbar=no,menubar=no,scrollbars=no,resizable=no,
Location=no,status=no ";)
Write a line
}
-->
</script>
<body >
... Any page content ...
</body>

A function Openwin () is defined here, and the function content is to open a window. There is no use before calling it. How to call it?
Method One: <body > Browser pop-up window when reading the page;
Method Two: <body > Browser pop-up window when leaving the page;
Method Three: Call with a connection: <a href= "#" > Open a Window </a>
Note: The "#" used is a virtual connection.
Method Four: Call with a button: <input type= "button" value= "open Window" >

"The main window opens the file 1.htm, while the small window pops up page.html"
Add the following code to the main window
Copy Code code as follows:

<script language= "java Script" >
<!--
function Openwin () {
window.open ("page.html", "", "width=200,height=200";)
}
-->
</script>

Add <body>: <a href= "1.htm" >open</a> can.

"timed off control of the pop-up window"
Next we have some control of the pop-up window, the effect is better. If we add a small piece of code to the pop-up page (note is added to the page.html HTML, not the main page, otherwise ...) So that it automatically shuts down in 10 seconds, is it cooler?
First, add the following code to the
Copy Code code as follows:

<script language= "java Script" >
function Closeit () {
SetTimeout ("Self.close ()", 10000)//MS
}
</script>

Then, then use <body > This sentence to replace page.html in the middle of some <BODY> this sentence on it. (Don't forget to write this sentence!) The function of this sentence is to call the code that closes the window, and then close the window itself after 10 seconds. )

"Add a close button to the pop-up window"
Copy Code code as follows:

<form>
<input type= ' BUTTON ' value= ' closed '
</form>

Oh, now more perfect!

"contains pop-up windows--one page two windows"
The example above contains two windows, one is the main window and the other is a pop-up window.
With the example below, you can do the above in one page.
Copy Code code as follows:

<script language= "java SCRIPT" >
function Openwin ()
{
Openwindow=window.open ("", "Newwin", "height=250,width=250,toolbar=no,scrollbars=" +scroll+ ", menubar=no";);
Write a line
OpenWindow.document.write ("<TITLE> example </TITLE>";)
OpenWindow.document.write ("<body bgcolor= #FFFFFF >";)
OpenWindow.document.write ("<H1>Hello!OpenWindow.document.write ("New window opened!";)
OpenWindow.document.write ("</body >";)
OpenWindow.document.write ("</HTML>";)
OpenWindow.document.close ()
}
</script>
<body>
<a href= "#" > Open a Window </a>
<input type= "button" value= "open Window" >
</body>

Look at the code inside OpenWindow.document.write () is not standard HTML? Just write more lines in the format. Be sure to note that one or fewer tabs will have an error. Remember to end with OpenWindow.document.close ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.