Javascript popup window script sometimes is useful for adding a popup window to your pages. When the user clicks on a link, a new window opens and displays a page.
You can use this function like this:
1
2
3
|
<a href="/index.html" title="Free code and tutorials"
onclick="return openWindow(this, {width:790,height:450,center:true})"
Free code and tutorials</a>
|
There are some available optional parameters which are passed as a second object parameter to this Javascript open window function (look above):
- width
- height
- left
- top
- center
- name
- scrollbars
- menubar
- locationbar
- resizable
Source code for webtookit.openwindow.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/**
*
* Javascript open window
* http://www.webtoolkit.info/
*
**/
function openWindow(anchor, options) {
var args = '';
if (typeof(options) == 'undefined') { var options = new Object(); }
if (typeof(options.name) == 'undefined') { options.name = 'win' + Math.round(Math.random()*100000); }
if (typeof(options.height) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
args += "height=" + options.height + ",";
}
if (typeof(options.width) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
args += "width=" + options.width + ",";
}
if (typeof(options.fullscreen) != 'undefined') {
args += "width=" + screen.availWidth + ",";
args += "height=" + screen.availHeight + ",";
}
if (typeof(options.center) == 'undefined') {
options.x = 0;
options.y = 0;
args += "screenx=" + options.x + ",";
args += "screeny=" + options.y + ",";
args += "left=" + options.x + ",";
args += "top=" + options.y + ",";
}
if (typeof(options.center) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
options.y=Math.floor((screen.availHeight-(options.height || screen.height))/2)-(screen.height-screen.availHeight);
options.x=Math.floor((screen.availWidth-(options.width || screen.width))/2)-(screen.width-screen.availWidth);
args += "screenx=" + options.x + ",";
args += "screeny=" + options.y + ",";
args += "left=" + options.x + ",";
args += "top=" + options.y + ",";
}
if (typeof(options.scrollbars) != 'undefined') { args += "scrollbars=1,"; }
if (typeof(options.menubar) != 'undefined') { args += "menubar=1,"; }
if (typeof(options.locationbar) != 'undefined') { args += "location=1,"; }
if (typeof(options.resizable) != 'undefined') { args += "resizable=1,"; }
var win = window.open(anchor, options.name, args);
return false;
}
|