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

Answers:

Answer

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: http://jqueryui.com/dialog/#default

Answer

use window.confirm instead of alert

if (window.confirm('If you click "ok" you would be redirected . Cancel will load this website ')) 
{
window.location.href='https://www.google.com/chrome/browser/index.html';
};
Answer

That's not possible to put clickable links in alert windows. The closest thing you could do is using a modal window, like this: http://twitter.github.io/bootstrap/javascript.html#modals

Answer

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.

Answer

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.

Answer

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.

Reference

Answer

This is a method with Jquery's Dialog

<html>
  <head>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <style></style>
  </head>
     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
<script src='template/js/jquery.textarea-expander.js'></script>
 <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript">
// <---- VENTA√ĎAS DE PARAMETERES---->
$(document).ready(function() { 
var regex,v,l,c,b,i,contapara=3;




$( "#wnd_Addparam" ).dialog({
            autoOpen: false,
            height: 'auto',
            width: 350,
            modal: true,
            resizable:false,
            buttons: {
                "Link": function() {
                   location.href="http://stackoverflow.com/questions/16973240/link-in-alert-boxes-javascript";
    return false;  },
                Cancel: function() {
                $( this ).dialog( "close" );
                }
            },
            close: {}
        });


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


                    });
</script>
  <body>

<div id="wnd_Addparam" title="Information" ></div>
</body>
</html>
Answer

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'))
   {
   window.open('http://www.google.com', '_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');
a.target='_blank';
a.href='https://www.google.com';

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

????

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.