JavaScript opens new Window method
window.open (' http://www.onesheng.cn ');
"1, the most basic popup window code"
In fact, the code is very simple:
<script language= "JavaScript" > <!-- window.open (' smsyun.html ')--
Because it's a javascripts code, they should be placed between <script language= "JavaScript" > tags and </script>
。 <!--and is useful for browsers with low versions, where the code in the tags is not displayed as text in these old browsers. To raise
Into this good habit ah.
window.open (' smsyun.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, absolute path (http://www.onesheng.cn), and relative path (..) should be indicated before. /) 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,
, especially the page code is long, and want to make the page pop up as far as possible forward.
"2, after setting the popup window"
Let's talk about the settings for the popup window. Just add a little something to the code above.
Let's customize the appearance of this pop-up window, size, pop-up position to fit the specific situation of the page.
<script language= "JavaScript" > <!-- window.open (' smsyun.html ', ' newwindow ', ' height=100, width= Top=0,left=0, Toolbar=no, menubar=no, Scrollbars=no, Resizable=no,location=no, Status=no ') //write a line -
Parameter explanation:
<script language= "javascript" > JS script start; window.open the command to pop up a new window; ' page.html ' The filename of the pop-up window, the name of the ' NewWindow ' pop-up window (not the file name), non-mandatory, available null ' instead of; height=100 window height; width=400 window width; The top=0 window is the pixel value above the screen; The Left=0 window is from the left side of the screen Width=250,toolbar=no,scrollbars= "+scroll+", Menubar=no "); Write a line of OpenWindow.document.write ("<title>smsyun studio </TITLE>") OpenWindow.document.write ("<body bgcolor= #ffffff > ") OpenWindow.document.write ("
Look at the code inside OpenWindow.document.write () is not the standard HTML? Just write more lines in the format. Pay attention to one more label or one less tag and there will be an error. Remember to end with OpenWindow.document.close ().
"9, the ultimate application-popup window of the cookie control" &NBSP;
Recall, the above pop-up window is cool, but there is a little trouble (immersed in joy, must not find it?) For example, if you put the above script in a page that needs to be frequently passed (such as the homepage), then each time you refresh the page, the window will pop up once, is it annoying? :-(, is there a way out? yes! ;-) Follow me. We can use cookies to control it. First, add the following code to the <HEAD> area of the main page HTML:
<script> function Openwin () {window.open ("page.html", "", "width=200,height=200")} function get_ Cookie (name) {var search = Name + "=" var returnvalue = ""; if (Document.cookie.length > 0) { offset = document.cookie.indexOf (search) if (offset =-1) { offset + = SE Arch.length end = Document.cookie.indexOf (";", offset); if (end = =-1) end = Document.cookie.length; Returnvalue=unescape (document.cookie.substring (offset,end)) } } return returnvalue; function Loadpopup () { if (Get_cookie (' popped ') = = ') { openwin () document.cookie= "Popped=yes" } }
Then, with <body onload= "Loadpopup ()" > (note not openwin but Loadpop!) Replace the main Page <BODY> this sentence can be. You can try refreshing this page or re-entering the page, and the window will never pop up again. The real pop-only-once!.
How to open a new window using JavaScript