简体   繁体   English

消息中带有链接的确认对话框?

[英]Confirmation Dialog with Link in message?

Sorry if this is a silly question (I am still new to web development), but is it possible to have a link in a basic confirmation dialog message? 抱歉,这是一个愚蠢的问题(我对Web开发还是很陌生),但是在基本的确认对话框消息中是否可以有链接?

Right now, I have a basic confirmation popup 现在,我有一个基本的确认弹出窗口

if (confirm("Bunch of text here"))
...

But a customer wants me to add a link in that confirmation box which would open in a new window. 但是客户希望我在该确认框中添加一个链接,该链接将在新窗口中打开。 Adding html tags in the message doesn't work since it's a message string. 在邮件中添加html标签不起作用,因为它是邮件字符串。

Any suggestions would be appreciated. 任何建议,将不胜感激。

Thanks! 谢谢!

You could make a modal and display it like that, or, even simpler, use bootstrap's built in modal. 您可以制作一个模态并像这样显示它,或者甚至更简单些,使用bootstrap内置的模态。

HTML: HTML:

<div class="button">Click</div>

<div class="overlay">

    <div class="modal"></div>

</div>

CSS: CSS:

.button {
    background-color: #aa0000;
    color: #fff;
    padding: 5px 40px;
    display: inline-block;
    cursor: pointer;
}

.overlay {
    background-color: rgba(0, 0, 0, 0.8);
    position: fixed;
    height: 100%;
    width: 100%;
    display: none;
    top: 0;
    left: 0;
}
.modal {
    left: 50%;
    margin-left: -100px;
    top: 50%;
    margin-top: -100px;
    background-color: #fff;
    position: fixed;
    height: 200px;
    width: 200px;
}

JS: JS:

$(function() {

var button = $('.button'),
    overlay = $('.overlay'),
    message = 'Message text',
    modal = $('.modal');

button.on('click', function() {
    overlay.css('display', 'block');
    modal.html( message + '<a href="http://google.com"' + 'target="_blank">' + 'link' +  '</a>');
});

});

http://jsfiddle.net/HNe95/ http://jsfiddle.net/HNe95/

That's not possible with the Javascript's confirm function. 使用JavaScript的confirm功能是不可能的。 In order to do that you need a custom modal dialog. 为此,您需要一个自定义的模态对话框。

If you use jQuery, you could create one by use one of these: vex , alertify , and apprise to name a few. 如果你使用jQuery,您可以通过使用其中之一创建一个: VEXalertify ,并通知仅举几例。

If you don't use jQuery, you can create one by applying some CSS and Javascripts for events. 如果您不使用jQuery,则可以通过为事件应用一些CSS和Javascript来创建一个。 You could also follow this guide . 您也可以遵循本指南

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM