How to redirect to a particular URL after click ok in alert message.

vishal jaiswal
Tera Contributor

How to redirect to a particular URL after click ok in alert message?

Please help in this.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vishal,

you should use confirm box for this.

An alert does not return a value, in fact returns undefined so the easiest way is conditioning the alert like this

if(!alert("Your text here"){

var url = 'URL Here'; // pass your url here
g_navigation.open(url, '_blank');

}


Or another better way is using confirm() javascript function like this

if(confirm("your text here")){

var url = 'URL Here'; // pass your url here
g_navigation.open(url, '_blank');

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Vishal,

you should use confirm box for this.

An alert does not return a value, in fact returns undefined so the easiest way is conditioning the alert like this

if(!alert("Your text here"){

var url = 'URL Here'; // pass your url here
g_navigation.open(url, '_blank');

}


Or another better way is using confirm() javascript function like this

if(confirm("your text here")){

var url = 'URL Here'; // pass your url here
g_navigation.open(url, '_blank');

}

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur

thanks a ton!

it works 🙂