Collection: JavaScript page essence code-pop-up window production and application techniques

Source: Internet
Author: User

"1, normal pop-up window" <script language=javascript> <!--window.open (' page.html ')--> </SCRIPT>

<!--and--> are for some versions of browsers that do not display the code in the label as text in these old browsers

Come out. Both single and double quotes are OK, just don't mix.

"2, after the Set pop-up window"
<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 ')//written in one line--> </SCRIPT>

Parameter explanation:

<script language=javascript> js script started;
window.open the command to eject a new window;
The filename of the ' page.html ' pop-up window;
' NewWindow ' pop-up window name, not required, available empty ' instead;
height=100 window height;
width=400 window width;
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

"3, use function to control pop-up window" Below is a complete code.

"4, pop-up 2 windows at the same time"
Change the source code slightly: <script language=javascript> <!--function Openwin () {window.open (page.html, NewWindow, height= width=100, Top=0, Left=0,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, Location=no, Status=no)//written in one line Windo W.open (page2.html, NewWindow2, height=100, width=100, top=100, Left=100,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no, Location=no, Status=no)//written in one line}//--> </script> to avoid the pop-up of the 2 window overlay, use top and left to control the pop-up position do not cover each other.  The last four methods mentioned above can be invoked. Note: The name of the 2 windows (NewWindows and NewWindow2) is not the same, or simply all empty.

"5, the main window to open the file 1.htm, while pop-up small Windows page.html"

The following code is added to the main window

"6, pop-up window of the timing off control"

Below 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 that it is added to the page.html HTML, not the main page, otherwise ...), let it automatically close in 10 seconds is not cooler. First, add the following code to the

"7, add a Close button in the pop-up window"
<FORM> <input type= ' BUTTON ' value= ' close ' onclick= ' window.close () ' > </FORM>

"8, included pop-up window-one page two windows"
With the example below, you can do the above in one page.   Software Development Network  www.mscto.com 

  Recall that the pop-up window above is cool, but it's a little bit of a problem. For example, if you put the above script in a page that needs to be frequently  , such as the homepage, then each time you refresh the page, the window will pop up once, is not very annoying. :-(  Solutions:  We can use cookies to control it. First, add the following code to the <HEAD> area of the homepage HTML: <script>  function openwin () {  window.open (page.html,,width =200,height=200)  }  Function get_cookie (Name)  {  var search = name  + =  var returnvalue = ;  if  (documents.cookie.length > 0)   {  Offset = documents.cookie.indexof (search)   if  (offset != -1)  {  offset += search.length  End = documents.cookie.indexof (;,  offset);  if  (end == -1)   end = documents.cookie.length;  Returnvalue=unescape ( Documents.cookie.substring (offset, end))  } }  return returnvalue; }  function  loadpopup () {  if  (Get_cookie (' popped ') = = ') {  Openwin ()   Documents.cookie=popped=yes } }  </script>  Then, with <body onload=loadpopup () > (Note that it's not openwin but Loadpop.) Replace the main page of the original   <BODY> this sentence can be. You can try to refresh the page or re-enter the page, and the window will never pop again. The real   pop-only-once.   Finished.

 

Related Article

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.