use*_*459 25 javascript jquery
我有一个简单的问题.我有以下代码:
alert("Are you sure you want to add: \n" + redirURL + "?");
Run Code Online (Sandbox Code Playgroud)
变量redirURL是一个实际的工作URL.我希望它是'可点击的'
先感谢您
小智 24
用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';
};
Run Code Online (Sandbox Code Playgroud)
小智 9
您只能在警报功能中显示文本.如果你想放一个url,你可以使用jquery的对话框功能.以下是一些代码示例:http://jqueryui.com/dialog/#default
如果您想在新窗口中打开警报链接,请使用以下代码:
if (window.confirm('Ok to Confirm, Cancel to Stay here'))
{
window.open('http://www.google.com', '_blank');
};
Run Code Online (Sandbox Code Playgroud)
请注意,大多数浏览器会将这些链接视为弹出链接。
还有一个替代方案,两者的工作原理相同,请在下面找到它:
//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();
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67948 次 |
| 最近记录: |