preventDefault() in window.close() does not prevent location change

3 posts, 0 answers
  1. Constantin
    Constantin avatar
    2 posts
    Member since:
    Dec 2016

    Posted 02 Dec 2016 Link to this post

    Hey there,

    I'm using the Dialog widget and want to prevent the close button from changing the `window.location`.

    So I use the following code to achieve it:

    01.dialogConfig = {
    02. 
    03.    // ...
    04. 
    05.    close: function(e) {
    06.      console.log("close clicked");
    07.      e.preventDefault(true);
    08.  }
    09.}

    I ran the code in the debugger and the preventDefault() call is indeed fired. Still, the window.location changes to '#' which changes the route in my Angular web app.

    Any help appreciated.

    Thanks & Cheers,

    Constantin

     

  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3710 posts

    Posted 06 Dec 2016 Link to this post

    Hi Constantin,

    Can you confirm there are no script errors when the app runs? This is the most common reason for the pound sign (#) to be appended to the URL. It is the value of the href attribute of the HTML element that is the close button and if the JavaScript that prevents the event bubbling fails, it will be appended to the URL.

    This works fine for me (see a test here and a short video with the expected behavior is attached) and in our demos (see here). Could you compare your setup with those examples to see what is the difference that causes the issue? A few differences I can see:

    • the preventDefault() method does not need an argument
    • generally, you do not need do call it because it will prevent the window from closing


    Regards,

    Marin Bratanov
    Telerik by Progress
    Kendo UI is ready for Visual Studio 2017 RC! Learn more.
  3. Constantin
    Constantin avatar
    2 posts
    Member since:
    Dec 2016

    Posted 23 Dec 2016 in reply to Marin Bratanov Link to this post

    Thanks, I worked it out without using `preventDefault()`.
Back to Top