In HTML, how do I open a index.html and then automatically open another page?

Source: Internet
Author: User

"1, the most basic popup window code" in fact the code is very simple: <script language= "JavaScript" ><!--window.open (' page.html ')-</SCRIPT> because this is a javascripts code, they should be placed between <script language= "JavaScript" >. <!--And--to some browsers with low versions, in which the code in the tag is not displayed as text in these old browsersTo.    It's a good habit to develop. window.open (' page.html ') is used to control the pop-up of the new window page.html if page.html does not match the main windowA path, preceded by the path, absolute path (http://) and relative path (.. /) are available.You can use both single and double quotes, just don't mix. This section of code can be added anywhere in the HTML,Before the earlier execution, especially the page code is long, and want to make the page pop up as far as possible forward. It is also possible that the sooner the earlier it is executed,Especially the page code is long, and want to make the page pop up as far as possible forward. "2, after the setting of the pop-up window" and then say the settings of the popup window. Just add a little something to the code above. Let's customize the bomb.Out of the window's appearance, size, pop-up position to fit 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 line-</SCRIPT> parameter explanation: <script language= "JavaScript" > JS script start;window.open the command that pops up the new window;The filename of the ' page.html ' pop-up window;The name of the ' NewWindow ' pop-up window (not the file 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 is displayed;Menubar,scrollbars represents the menu bar and scroll bar.Resizable=no whether the window size is allowed to change, yes is allowed;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 already open), yes is allowed;</SCRIPT> js Script End "3, use function to control pop-up windows" Below is a complete code: <script language= "JavaScript" ><!--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 onload= "Openwin ()" > ... 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 invoke it?Method One: <body onload= "Openwin ()" > Browser to read the page when the pop-up window;Method Two: <body onunload= "Openwin ()" > Pop-up window when the browser leaves the page;Method Three: Call with a connection: <a href= "#" onclick= "Openwin ()" > Open a Window </a>Note: The "#" used is a virtual connection.Method Four: Call with a button: <input type= "button" onclick= "Openwin ()" value= "Open the windowPort ">" 4, Pop up 2 windows at the same time "slightly change the source code:<script language= "JavaScript" ><!--function Openwin () {window.open ("page.html", "NewWindow", "height=100, width=100,Top=0,left=0,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no,Location=no,status=no ")Write a linewindow.open ("page2.html", "NewWindow2", "height=100, width=100,Top=100,left=100,toolbar=no, Menubar=no, Scrollbars=no, Resizable=no,Location=no,status=no ")Write a 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. Finally, with the topFour ways to call.Note: The name of the 2 windows (NewWindows and NewWindow2) is not the same, or altogether empty. Ok?"5, main window open file 1.htm, and pop up small window page.html" The following code to join the main window <script language= "JavaScript" ><!--function Openwin () {window.open ("page.html", "", "width=200,height=200")}-</script>Join <body> Area:<a href= "1.htm" onclick= "Openwin ()" >open</a>. "6, pop-up window of the timing of the control" under the window we have some control, the effect is better. If we add a little piece of code to the popup page(Note that it is added to the HTML of page.html, not the main page, otherwise ...), so that it automatically shuts down after 10 seconds is notIt's even cooler?First, add the following code to the <script language= "JavaScript" >function Closeit () {SetTimeout ("Self.close ()", 10000)//MS}</script>Then, with <body onload= "Closeit ()" > This sentence instead of page.html the central Plains have a <BODY> this sentence can beThe (This sentence must not forget to write Ah!) The function of this sentence is to invoke the code to close the window, and after 10 seconds, close theWindow. )"7. Add a Close button to the pop-up window" <form><input type= ' BUTTON ' value= ' off ' onclick= ' window.close () ' ></form> Oh, now more perfect! "8, within the pop-up window---a page two windows," The above example contains two windows, one is the main window, the other is a small pop-up window. Using the example below, you canComplete the above effect on one page.<script language= "JavaScript" >function Openwin (){Openwindow=window.open ("", "Newwin", "height=250,Width=250,toolbar=no,scrollbars= "+scroll+", Menubar=no ");Write a lineOpenWindow.document.write ("<TITLE> example </TITLE>")OpenWindow.document.write ("<body bgcolor= #ffffff >")OpenWindow.document.write ("OpenWindow.document.write ("New window opened!")OpenWindow.document.write ("</BODY>")OpenWindow.document.write ("</HTML>")OpenWindow.document.close ()}</SCRIPT><body><a href= "#" onclick= "Openwin ()" > Open a Window </a><input type= "button" onclick= "Openwin ()" value= "open Window" ></body>Can Pay attention to one more label or one less tag and there will be an error. Remember to end with OpenWindow.document.close ()Ah."9, the ultimate application-pop-up window cookie control" recall, the above pop-up window although cool, but a little bit of a problem (immersed in the joy, must not find it?) ) thanIf you put the above script on a page that needs to go through frequently (such as the homepage), each time you refresh the page, the windowWill pop up once, isn't it very annoying? :-(Is there a way to solve it? Of course! We can use cookies to control it. First, add the following code to the main page<HEAD> area of 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.lengthEnd = 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 " }< c9>} </script> then, with <body onload= "Loadpopup ()" > (note not openwin but Loadpop!) Replace the original <BODY> in the main page . You can try refreshing this page or re-entering the page, and the window will never pop up again. The real pop-only-once!.

I hope my answer is helpful to you.

In HTML, how do I open a index.html and then automatically open another page?

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.