Struppi: event-Objekt in Funktionen geht nicht

Beitrag lesen

Hallo!

Bei mir tritt ab und zu das Problem auf, dass das event-Objekt nicht zu existieren scheint. (Internet Explorer 6.0.2600).

Zum Biespiel in diesem Code:

<html>
<head>
<script type="text/javascript">
var m = 0;
function startUp() {
 c = window.createPopup();
 c.document.write("hallo");
 c.document.body.onmousedown = function() {parent.m=1};
 c.document.body.onmouseup = function() {parent.m=0};
 c.show(200, 200, 400, 400);
 window.setInterval('moveDa()', 20);
}

function moveDa() {
 if (m == 1) {
  daX = window.event.x; //  <==
  daY = window.event.x; //  <==

Da tritt ja auch kein event auf. Du musst das bei dem event abfragen (nebenbei benutzt du reinen IE Code):

var m = 0;
var daX, daY;
function startUp()
{
    document.onmousedown = function(e)
    {
        daY = e ? e.pageY : window.event.y;
        daX = e ?  e.pageY : window.event.x;
        parent.m=1;
        moveDa();
    };
    document.onmouseup = function(e)
    {
       daY = e ? e.pageY : window.event.y;
       daX = e ?  e.pageX : window.event.x;
       parent.m=0;
       moveDa()
    };
}
function moveDa() {
 if (m == 1) {
  window.status = daX + '-' +daY;
 }
}
startUp();

Aber ich befürchte du suchst startDrag endDrag. Aber da musst du selber mal nach suchen mit dem evente kenne ich mich nicht so aus.

Struppi.