Toon posts:

[js] Verkrijgen van dimensies van popupwindow

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik wil via javascript van een eerder geopend window de dimensies opvragen, zodat ik deze kan wegschjrijven in een cookie, om deze weer uit te lezen bij de volgende keer gebruik.
Maar ik krijg het niet voor elkaar om de gegevens van het popupwindow uit te lezen, ik krijg alleen maar de waarden gelezen van het mainwindow.
Heb vvel gezocht en geprobeerd, maar ik kom er niet uit. Help please :)

Heb de volgende code :
code:
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<html>
<head>
<script type="text/javascript">
function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

function startViewer(){
var width = readCookie('width');
var height = readCookie('height');
popupWindow = window.open('http://10.185.46.131:9080/cm/servlet/CMServlet?docid=B07116AA.AAF&user=C_RH03FAKV&passw=4iUh%20Hk3','Viewer','width=' + width + ',height=' + height + ',resizable=yes');
if (window.focus){popupWindow.focus()}
}

function closeViewer(){
var width = popupWindow.innerWidth;
var height = popupWindow.innerHeight;
alert(height);
popupWindow.close();
createCookie('width',width,365);
createCookie('height',height,365);
return false;
}

function alertSize(windowname) {
  var myWidth = 0, myHeight = 0;
  if( typeof( windowname.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = windowname.innerWidth;
    myHeight = windowname.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  window.alert( 'Width = ' + myWidth );
  window.alert( 'Height = ' + myHeight );
}
</script>
</head>

<body>
<form>
<input type="button" value="View document"
onclick="startViewer()" >
</form>
<br>
<form>
<input type="button" value="Close document"
onclick="closeViewer()" >
</form>
<form>
<input type="button" value="Show width"
onclick="alertSize('popupWindow')" >
</form>
</body>
</html>

De startViewer opent het window, en ik ben dus aan het testen met 'alertSize'.
Hoe kan ik aan het popupwindow vragen hoe groot deze is ???

  • akaIDIOT
  • Registratie: Januari 2005
  • Laatst online: 03-10-2025
Je slaat je popupwindow al op in een variabele. Als je deze nou eens bovenaan je JS declareert, zou je er later ook nog dingen aan moeten kunnen vragen. Wat je nu doet is het window opvragen wat de naam draagt van je variabele, die naam heb je nergens aan dat window toegekend.

Ik ken de functie window.open niet uit me hoofd, maar geef je die niet de naam "Viewer", je zou dan alertSize('Viewer') kunnen proberen.

*stu!ter* *boink*


Verwijderd

Topicstarter
Bedankt. Dat hielp wel iets.

ik gebruik nu
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function getWidth() {
  return (
        popupWindow.innerWidth ? popupWindow.innerWidth : 0,
        popupWindow.document.documentElement ? popupWindow.document.documentElement.clientWidth : 0,
        popupWindow.document.body ? popupWindow.document.body.clientWidth : 0
    );
}
function getHeight() {
    return (
        popupWindow.innerHeight ? popupWindow.innerHeight : 0,
        popupWindow.document.documentElement ? popupWindow.document.documentElement.clientHeight : 0,
        popupWindow.document.body ? popupWindow.document.body.clientHeight : 0
    );
}

En dat werkt prima in IE en FF.
Nu wil ik ook de positie van het window nog opvragen. Ik krijg het idee dat ik dit sowieso niet direct kan opvragen, maar moet berekenen. Alleen de vraag is hoe. Iemand ?