I want to create a session timeout function for a payment page, where the timer will be displayed in my webpage and after 5 minutes, the payment session will expire and user is redirected to the previous page. I am using angular 4 for my front end, so using href
is not entertained, i want a solution involving just javascript
and routerLink
and typescript
. Any suggestions?
I am using this function to show the timer on webpage, its working but not am unable to use routerLink here to redirect to previous page.
paymentSessionTimer() {
let downloadButton = document.getElementById("paymentSession");
var counter = 600;
var newElement = document.createElement("p");
newElement.innerHTML = "10";
var id;
this.redirectFlag = "false";
downloadButton.parentNode.replaceChild(newElement, downloadButton);
id = setInterval(function() {
counter--;
if(counter < 0) {
newElement.parentNode.replaceChild(downloadButton, newElement);
clearInterval(id);
this.redirectFlag = "true";
//this.router.navigate(['../search']);
} else {
newElement.innerHTML = counter.toString() + " seconds left.";
}
}, 1000);
this.router.navigate(['../previous']);
}