javascript control pop-up window size, and maximize

The most basic pop-up window [Code] 
fact, the code is very simple: 
<SCRIPT LANGUAGE = "JavaScript"> 
<-! 
Window.open ( 'page.html') 
-> 
</ SCRIPT>

The code is used to maximize

<SCRIPT the LANGUAGE = "JavaScript"> 
<-! 
The window.open ( 'page.html', '', '=. 1 Fullscreen', Top = 0, left = 0, Toolbar = Yes, MenuBar = Yes, scrollbars = Yes , resizable = Yes, LOCATION = Yes, Status = NO ') 
-> 
</ SCRIPT> 
because this is a javascript code, so they should be placed between the <SCRIPT LANGUAGE = "javascript"> tag and </ script>. <! - and -> for some low version of the browser function in these older browsers that do not support javascript, will not label code as text displayed. 
Window.open ( 'page.html') for controlling a new pop-up window page.html, if not page.html and the main window in the same path, the front should be stated, the absolute path (http: //) and relative path (../) can be. 
All OK, just do not mix with single and double quotes. 
This piece of code can be added anywhere in the HTML, is added to the <head> and </ head> It can also be between the more forward position to perform sooner, especially when long page of code, want to make the page pop-up to try to put forward.

After the pop-up [] is provided 
below the window and then talk about the appearance of the pop-up settings. Beyond just the above code to add a little something on it. 
We customize the appearance of the pop-up window, the size, the pop-up position to accommodate the specific circumstances of the page. 
<SCRIPT LANGUAGE = "JavaScript:> 
<-! 
js script ends. [Pop-up window with the control function]  The following is a complete code. <html> 























<head> 
<Script the LANGUAGE = "JavaScript"> 
<-! 
function openwin () { 
the window.open ( "page.html", "NewWindow", "height = 100, width = 400, Toolbar = NO, NO = MenuBar ,
scrollbars = NO, resizable = NO, LOCATION = NO, NO Status = ";) 
// row written 

-> 
</ Script> 
</ head> 
<body the onload =" openwin () "> 
... arbitrary page content ... 
</ body> 
</ HTML> 
this defines a function openwin (), a function of the content is to open a window. No use before calling it. How to call it? 
Method a: <body onload = "openwen ( )"> pop-up browser to read the page window; 
Method two: <body onunload = "openwen ( )"> pop-up browser to leave the page; 
Method three: with a connect call: <a href="#" onclick="openwin()"> open a window </a> 
Note: Use the "#" is the virtual connection. 
Method IV: a button to call: <input type = "button" onclick = "openwin ()" value = "http://blog.netbei.com/ open the window"> 

[Main Window 1.htm file open, while a small pop-up window page.html] 
the following code to the main window <head> area: 
<Script Language = "JavaScript"> 
<-! 
Function openwin () { 
the window.open ( " page.html "," "," width = 200 is, height = 200 is ";)

// -> 
</ Script> 
added <body> area: <a href =" http://blog.netbei.com/ 1.htm "onclick =" openwin () "> open </a> can be. 

[Timing pop-up window of the closed control] 
Here we have some control on the pop-up window, the effect is better. If we then short code into the pop-up page (note the page.html added to the HTML, not the main page, or else ...), it is not cool to automatically shut down in 10 seconds? 
First, the following code is added to the file page.html <head> area: 
<Script Language = "JavaScript"> 
function closeit () { 
the setTimeout ( "self.close ()", 10000) // ms 

</ Script> 
Then, then the <body onload = "closeit () "> This sentence in place of any original page.html <BODY> can be a sentence. (This sentence must not forget to write ah! This is a call to action to close the window of the code, after the 10 seconds to close the window itself.) 

[In the pop-up window with a button closure] 
<form> 
<the INPUT the TYPE = 'BUTTON' value = 'off' the onClick = 'the window.close ()'> 
</ form> 
Oh, now more perfect! 

Pop-up window containing the [-] one page two windows 
above example contains two windows, one is the main window, the other window is a small pop. 
By the following example, you can accomplish the above results within a page. 
<HTML> 
<head> 
<SCRIPT the LANGUAGE = "JavaScript"> 
function openwin () 

OpenWindow the window.open = ( "", "newwin", "height = 250, width = 250, Toolbar = NO, scrollbars =" Scroll + + ", MenuBar = NO";); 
// write line 
OpenWindow.document.write ( "<TITLE> example </ TITLE>";

OpenWindow.document.write ( "<Hl> the Hello </ h1 of>!";)
OpenWindow.document.write ( "the Opened window New!";)
OpenWindow.document.write ( "</ the BODY>";)
OpenWindow.document .write ( "</ the HTML>";)
OpenWindow.document.close () 

</ Script> 
</ head> 
<body> 
<a href="#" onclick="openwin()"> open a window </ A> 
<INPUT type = "Button" the onclick = "openwin ()" value = "http://blog.netbei.com/ open the window"> 
</ body> 
</ HTML> 
See OpenWindow.document.write () inside the code is not standard HTML? Just follow the format write more lines can be. Do pay attention to more than one label or less a label error will occur. Remember with OpenWindow.document. close () end ah.

[Ultimate application - Cookie Control pop-up window] 
Recall that although the pop-up window above the cool, but there are little problems such as the above script you will need to put a (you are immersed in the joy, certainly did not find it?) frequent passing pages (eg Home), then each time you refresh the page, a window will pop up once, it is not very annoying? There are ways to solve it? Yes! Follow me. We use Cookie to control what you can. 
首先,将如下代码加入主页面HTML的<HEAD>区: 
<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, the <body onload = "loadpopup () "> ( noted but not openwin loadpop ah) replacing any original home page <BODY> can be one which . You can try to refresh the page or re-enter this page, the window never pops up. True Pop-Only-Once! 
I write to you, the pop-up window production and application skills basically be finished, we want to create web pages is to help a friend I was very satisfied. 
It should be noted, JS script in the best case before and after consistent. 

No menu, toolbar, pop-up window address bar: 

<Script Language = "JavaScript"> 
<-! 
Var gt = unescape ( '% 3E'); 
var popup = null; 
var over = "Pop-up the Launch Navigator" ; 
popup = the window.open ( '', 'popupnav', 'width = 500, height = 500, resizable = 0, scrollbars = Auto'); // width = 500, height = 500 width and length of the window 
if (popup ! = null) { 
IF (popup.opener == null) { 
popup. 


// --> 
</script>

Reproduced in: https: //my.oschina.net/kt431128/blog/224712

Guess you like

Origin blog.csdn.net/weixin_34310369/article/details/91952479