Отслеживать, какой динамический тег c был добавлен в javascript - PullRequest
1 голос
/ 01 апреля 2020

У меня нет большого опыта работы с JavaScript.
Если пользователь уже нажал на этот якорный тег Dynami c, я хочу, чтобы он предупреждал его с помощью другого типа подтверждающего сообщения.

<table class="table table-bordered">
    <thead>
        <tr>
            <th scope="col">Dataset</th>
        </tr>
    </thead>
    <tbody>

        @foreach ($dumpDb as $key => $value)
        <tr>
            <td scope="row">{{ $value->dataset }}
                <span>
                    <a class="downloadLink" href="{{Route('dump.downloadFile', ['id' => $value->dataset ])}}" onclick="return ConfirmDownload()"> Download </a>
                </span>
            </td>
        </tr>
        @endforeach

    </tbody>
</table>
<script type="text/javascript">
// dalifyDownloads - how many times a user can download file in 24hours. By default 5 files per day.
    function ConfirmDownload() {
        var dailyDownloads = {{ Auth::user()->dailyDownloads}};
        if (User has already pressed on this button) {
          var x = confirm("Are you sure you want to download this file?");
          if (x)
              return true;
          else
              return false;
        } else {
          // If User has not pressed on this button
            var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
            if (x)
                return true;
            else
                return false;
        }
    }
</script>

1 Ответ

1 голос
/ 01 апреля 2020

Вы можете отслеживать, используя переменную вне функции:

var pressed = false;

function ConfirmDownload() {
    var dailyDownloads = {{ Auth::user()->dailyDownloads}};
    if (!pressed) {      
      var x = confirm("Are you sure you want to download this file?");
      if (x){
          pressed = true;
          return true;
      }
      else
          return false;
    } else {
      // If User has not pressed on this button
        var x = confirm("Are you sure you want to download this file? Your daily download limit is " + dailyDownloads);
        if (x)
            return true;
        else
            return false;
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...