jQuery 警报框中的链接 javascript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16973240/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
link in alert boxes javascript
提问by user2101459
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'
变量 redirURL 是一个实际的工作 url。我希望它是“可点击的”
thank you in advance
先感谢您
采纳答案by Na?m Baki
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
您只能在警报功能中显示文本。如果你想放一个url,你可以使用jquery的对话框功能来实现。下面是一些代码示例:http: //jqueryui.com/dialog/#default
回答by warlord
use window.confirm
instead of alert
使用window.confirm
代替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';
};
回答by Antoine
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
不可能在警报窗口中放置可点击的链接。您可以做的最接近的事情是使用模态窗口,如下所示:http: //twitter.github.io/bootstrap/javascript.html#modals
回答by RichieHindle
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.
您不能将可点击的 URL 放在标准alert()
框中。相反,您可以使用“灯箱”,它是一个 HTML 弹出窗口 - 有任意数量的灯箱可用,您应该选择一个适合您网站/应用程序其余部分的灯箱。
回答by jterry
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.
我建议使用更强大的方法,如jQuery UI's dialog。
回答by PSL
It is not possible with window.alert that you are using. Instead you can try using dialog plugins like modal plugin from bootstrapor jquery ui dialog. Your hyperlink is an html where as alert box is non html component of the browser generated by browser's javascript.
您正在使用的 window.alert 是不可能的。相反,您可以尝试使用对话框插件,例如bootstrap 中的modal plugin或jquery ui dialog。您的超链接是一个 html,其中警告框是由浏览器的 javascript 生成的浏览器的非 html 组件。
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.
警报对话框应该用于不需要用户方面的任何响应的消息,除了消息的确认。
回答by Mirko Cianfarani
This is a method with Jquery's Dialog
这是一个带有 Jquery 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>