Results 1 to 2 of 2

Thread: window.event.returnValue

  1. #1
    Join Date
    Apr 2007
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default window.event.returnValue

    Problem:
    * "window.event.returnValue=x" >> does not work at every place in the code.
    * "window.event.returnValue=false;" >> Works always fine when it is NOT inside the "e.onerror = function()" or inside the e.onload = function()"

    Q: why it is working fine when the "event.returnValue=false;" is placed inside the "OnClickDone() but does not work when it is placed inside the e.onerror/e.onload functions?

    The code with explanation of the problem:

    function OnClickDone()
    {
    var i = 0;
    var e = document.createElement("img");//try to load img
    e.src = "http://...url.../groen.bmp";
    e.onerror = function()//can't load, so return event false.
    {
    window.event.returnValue=false;//does not work >>(the next page should not be loaded)
    alert("OFF Line");//works fine
    e = null;
    };
    e.onload = function()
    {
    window.event.returnValue=true;// it passes here, but does not do it.
    alert("ON Line");//work fine
    e = null;
    };

    Thanks,

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by blasius View Post
    "window.event.returnValue=x" >> does not work at every place in the code.
    Avoid the returnValue property: it's a Microsoft invention, and an unnecessary one at that. Instead, use a return statement with the same value. That is,

    Code:
    return x;
    The two are equivalent, but the latter is both shorter and better supported across browsers.

    "window.event.returnValue=false;" >> Works always fine when it is NOT inside the "e.onerror = function()" or inside the e.onload = function()"
    Some events cannot be cancelled, including the load event, but that's not the reason in this instance.

    Q: why it is working fine when the "event.returnValue=false;" is placed inside the "OnClickDone() but does not work when it is placed inside the e.onerror/e.onload functions?
    Only one event is ever active at one time - dispatched events are queued and processed in order. This means that the function, OnClickDone, and any other listeners for that event must finish executing before the next event is handled. By the time the error or load events fire for the image, the click event will have been completed long ago, therefore it cannot be cancelled.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •