Hannes S: event-Objekt in Funktionen geht nicht

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; //  <==
  c.show(daX, daY, 400, 400);
 }
}

</script>
</head>
<body>
<button onclick="startUp()">open</button>
<br>

<br>
</body>
</html>

Da wo die Variablen daX und daY ihren Wert erhalten, bekomme ich die Fehlermeldung  "Objekt erforderlich". Vielleicht steh ich einfach nur aufm Schlauch... bitte helft mir ;) !

Danke im Voraus, Hannes

  1. 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.

    1. Also besteht nicht die Möglichkeit ohne einen Event die Cursorposition abzufragen?

      1. Also besteht nicht die Möglichkeit ohne einen Event die Cursorposition abzufragen?

        http://selfhtml.teamone.de/javascript/sprache/eventhandler.htm#onmousemove

        1. Also besteht nicht die Möglichkeit ohne einen Event die Cursorposition abzufragen?

          http://selfhtml.teamone.de/javascript/sprache/eventhandler.htm#onmousemove

          Bin ich gar nicht drauf gekommen. Muss ich allerdings doppelt (im Hauptfenster und im createPopup) definieren. Danke! Aber nur aus Interesse: ohne Event gehts gar nicht, oder wie??

          mfg