link in alert boxes javascript

I have a simple question. I have the following code:

alert("Are you sure you want to add: \n" + redirURL + "?");

the variable redirURL is an actual working url. I would like it to be 'clickable'

thank you in advance



You can only display text in the alert function. If you want to put an url, you can do it by using jquery's dialog function. Here are some code examples:


use window.confirm instead of alert

if (window.confirm('If you click "ok" you would be redirected . Cancel will load this website ')) 

That's not possible to put clickable links in alert windows. The closest thing you could do is using a modal window, like this:


You can't put clickable URLs in a standard alert() box. Instead you could use a "lightbox", which is an HTML popup - there are any number of them available, and you should choose one that fits well with the rest of your site/applicaiton.


It's not possible in any "standard" web browser that I'm aware of.

I'd suggest using a more robust approach like jQuery UI's dialog.


It is not possible with window.alert that you are using. Instead you can try using dialog plugins like modal plugin from bootstrap or jquery ui dialog. Your hyperlink is an html where as alert box is non html component of the browser generated by browser's javascript.

The alert dialog should be used for messages which do not require any response on the part of the user, other than the acknowledgement of the message.



This is a method with Jquery's Dialog

   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
     <script src=""></script>
    <script src=""></script>
<script src='template/js/jquery.textarea-expander.js'></script>
 <link href="" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
$(document).ready(function() { 
var regex,v,l,c,b,i,contapara=3;

$( "#wnd_Addparam" ).dialog({
            autoOpen: false,
            height: 'auto',
            width: 350,
            modal: true,
            buttons: {
                "Link": function() {
    return false;  },
                Cancel: function() {
                $( this ).dialog( "close" );
            close: {}

                $( "#wnd_Addparam" ).dialog( "open" );


<div id="wnd_Addparam" title="Information" ></div>

If you want to open the Link on alert and that too in new window, Use the code below:

if (window.confirm('Ok to Confirm, Cancel to Stay here'))
   {'', '_blank');

Note that most browsers will treat these links as popup.


There is an alternative too, Both works same, find it below:

//write this above first
let a=document.createElement('a');'_blank';

//then use this code for alert
if (window.confirm('Ok to Confirm, Cancel to Stay here'))



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.