How to Disable Browser Refresh Button in Angular?
In this example, you will learn how to disable refresh button of browser using angular. This article goes in detailed on angular prevent browser refresh. i would like to share with you disable f5 in angular. i would like to show you angular disable browser refresh button. follow bellow step for how to stop page refresh in angular.
Here, i will give you simple example of disable f5 and browser refresh function in angular application. we will use window keyup and window keydown event to prevent browser page refresh in angular app.
You can easily prevent browser refresh in angular 7, angular 8, angular 8 and angular 9 application.
src/app/app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
ngOnInit(){
window.addEventListener("keyup", disableF5);
window.addEventListener("keydown", disableF5);
function disableF5(e) {
if ((e.which || e.keyCode) == 116) e.preventDefault();
};
}
}
Now you can run and check it.
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Create Custom Directive in Angular?
- How to Create Routing Module in Angular?
- Angular HttpClient with Observable Example
- Angular Material Stepper Example | Angular Material Stepper
- Angular Window Scroll Event Example
- Angular Input Blur Event Example
- Angular Input Keyup Event Example
- Angular Input Keypress Event Example
- Angular NgForm Example | NgForm Directive In Angular
- Angular NgIf Example | NgIf Directive In Angular