Read for a long time, finally arrived I think the actual combat part, the first is window.open, plainly is the pop-up window.
In terms of the basics:
| The code is as follows |
Copy Code |
Equivalent to <a href= "http://111cn.net" target= "Topframe" ></a> window.open ("Http://111cn.net", "topframe");
|
There is no future for equivalence, so there are other uses here, Topframe, which is the second argument that can pass in _self,_parent,top and _blank, while the second argument is not an existing window or frame, it reads the third parameter to determine The third parameter seems to be some of the less useful, mainly top,width,left,height position.
Like what:
| The code is as follows |
Copy Code |
window.open (' http://111cn.net ', ' _blank ', ' height=500, width=300, left=20, top=20 ');
|
A window pops up (but most of the time it's a harmonious fate)
In addition, the close () method closes the pop-up window (other windows are not authorized to operate), and moveto () ' Resizeto () is known by name.
If the window is blocked, it generally returns null and throws an error, so we can use
| code is as follows |
copy code |
var blocked = false; try { var pop = window.open (' http://111cn.net ', ' _blank ', ' height=500, width=300, left=20, top=20 '); if (pop = null) { blocked = true; } } catch (ex) { blocked = true; & nbsp if (blocked) { alert ("The pop was blocked"); } |
To detect if the window was blocked and prompted.
Then slightly with the knowledge of the previous toss a bit, specific in the source code can also write quite clear, code slag, do not blame.
Demonstrate
| The code is as follows |
Copy Code |
| <! DOCTYPE html> <meta charset= "UTF-8" > <title>Window-on</title> <body> <script> function NewWindow () { This.win = window.open (' http://111cn.net ', ' _blank ', ' height=500, width=300, left=20, top=20 '); } Newwindow.prototype = { Constructor:newwindow, Close:function () { This.win.close (); }, Resize:function () { This.win.resizeTo (300, 300); }, Moveto:function () { This.win.moveTo (100, 100); } } /* First way: Simple version var pops = window.open (' http://111cn.net ', ' _blank ', ' height=500, width=300, left=20, top=20 '); if (pop = = null) { Alert ("The pop was blocked!"); } */ /* The second way: more accurate * * var blocked = false; try { var pops = window.open (' http://111cn.net ', ' _blank ', ' height=500, width=300, left=20, top=20 '); if (pop = = null) { blocked = true; } catch (ex) { blocked = true; } if (blocked) { Alert ("The pop was blocked"); } </script> <input type= "button" value= "Hello Sky" onclick= "Windows = new NewWindow ();" /> <input type= "button" value= "Close" onclick= "windows.close ();"/> <input type= "button" value= "resize" onclick= "windows.resize ();"/> <input type= "button" value= "MoveTo" onclick= "Windows.moveto ();"/> </body> |