Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 打开外部链接上的模式弹出窗口_Javascript_Jquery - Fatal编程技术网

Javascript 打开外部链接上的模式弹出窗口

Javascript 打开外部链接上的模式弹出窗口,javascript,jquery,Javascript,Jquery,当用户点击外部链接时,我试图打开一个模式弹出窗口,如果点击按钮上的“是”,可以继续链接 如果没有,他将继续访问该网站。但我不知道如何判断,如果单击“确定”,他可以继续访问已单击的链接 以下是我迄今为止的代码: jQuery('a').filter(function() { return this.hostname && this.hostname !== location.hostname; }).click(function(e) { e.preven

当用户点击外部链接时,我试图打开一个模式弹出窗口,如果点击按钮上的“是”,可以继续链接

如果没有,他将继续访问该网站。但我不知道如何判断,如果单击“确定”,他可以继续访问已单击的链接

以下是我迄今为止的代码:


  jQuery('a').filter(function() {
    return this.hostname && this.hostname !== location.hostname;
  }).click(function(e) {
    e.preventDefault();
    if(this.hostname !== location.hostname)
    return Swal.fire({
      title: 'Are you sure?',
      text: "You won't be able to revert this!",
      icon: 'warning',
      showCancelButton: true,
      confirmButtonColor: '#3085d6',
      cancelButtonColor: '#d33',
      confirmButtonText: 'Yes, delete it!'
    }).then((result) => {
      if (result.isConfirmed) {

      }
    })
    {
      // if user clicks 'no' then dont proceed to link.
      e.preventDefault();
    };


我使用了jquery和swal的最新版本。但应该差不多

$(函数(){
var allLinks=$(“a”).filter(函数(){
返回this.hostname&&this.hostname!==location.hostname;
})。单击(功能(e){
e、 预防默认值();
游泳({
标题:“你确定吗?”,
文本:“您将要打开一个外部url。”,
图标:“警告”,
按钮:是的,
丹格莫德:没错,
})
。然后((结果)=>{
如果(结果){
//document.location.href=this.href;//如果希望在同一窗口中打开它
window.open(this.href);//将在新窗口中打开它
}
});
});
});

- 
- 

在你给出这个答案之前(非常感谢你)

事实上,我发现了一种方法:

window.location = this.href;

是否正确?

如果要在同一窗口中打开,则正确。如果您想在新窗口中打开它,请使用
窗口。请改为打开
。非常感谢,真正的问题是,我可以检索已单击链接的url吗?因此,我可以将其用于模式
中。href
将为您提供单击链接的url。