window.open encapsulation to make it better, and more compatible, many people say window.open incompatible, in fact, because can not be directly executed, must be triggered by the user manually; see Code:
| The code is as follows |
Copy Code |
| var Openwindow = function (URL, options) { var str = ""; if (options) { Options.height = Options.height | | 420; Options.width = Options.width | | 550; Options.left = Options.left | | ((screen.width-options.width)/2); The default is centered Options.top = Options.top | | ((screen.height-options.height)/2); The default is centered for (var i in options) { str + = ', ' + i + ' = ' + options[i]; } str = STR.SUBSTR (1); }; window.open (URL, ' connect_window_ ' + (+new Date), str);//parameter 1 is a URL, parameter 2 in order to be able to repeat the popup str = NULL; }; Demo 1: New window open Document.body.onclick = function () { Openwindow ("http://www.111cn.net/Rel=xuexb"); } Demo 2: Fixed width and center Document.body.onclick = function () { Openwindow ("http://www.111cn.net/Rel=xuexb", { width:888 }); } |