This is a migrated thread and some comments may be shown as answers.

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

2 Answers 980 Views
Window
This is a migrated thread and some comments may be shown as answers.
Constantin
Top achievements
Rank 1
Constantin asked on 02 Dec 2016, 03:07 PM

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 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 06 Dec 2016, 09:17 AM

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.
0
Constantin
Top achievements
Rank 1
answered on 23 Dec 2016, 11:05 AM
Thanks, I worked it out without using `preventDefault()`.
Tags
Window
Asked by
Constantin
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Constantin
Top achievements
Rank 1
Share this question
or