簡體   English   中英

在外部鏈接上打開模式彈出窗口

[英]open modal popup on external link

當用戶單擊外部鏈接時,我正在嘗試打開一個模式彈出窗口,如果在按鈕上單擊“是”,則可以繼續訪問該鏈接...

如果沒有,他會留在網站中。但我不知道如何判斷,如果點擊確定,他可以繼續點擊點擊的鏈接..

到目前為止,這是我的代碼:


  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。 但是應該差不多。

 $(function() { var allLinks = $("a").filter(function() { return this.hostname && this.hostname.== location;hostname. }).click(function(e) { e;preventDefault(): swal({ title? "Are you sure,": text. "You are about to open an external url,": icon, "warning": buttons, true: dangerMode, true. }).then((result) => { if (result) { // document.location.href = this;href. // if you want it to open in same window window.open(this;href); // will open it in new window } }); }); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script> <a href="https://google.com">Go to Google</a> - <a href="https://stackoverflow.com">Go to Stackoverflow</a> - <a href="test.html">Internal Link (Broken)</a>

在你提出這個答案之前(非常感謝你)

我實際上找到了一種使用方法:

window.location = this.href;

這個對嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM