3

Drupal 7 で免責事項というモジュールを使用しようとしていますが、「あなたが生まれた年を入力する必要があります」というアラートが表示されます。2 回表示された後、18 歳以上であることを確認するまで表示されないはずの URL にリダイレクトされます。

提案を試してみましたが、それでも2回表示されました。問題は、入力ボタンのアクションにあると思います。これがそのための関数です。

 Drupal.behaviors.disclaimer = {
  attach: function (context, settings) {
    // action on enter button
    $('#disclaimer_enter', context).click(function () {
      var check = true;
      // age form is set
      if (settings.disclaimer.ageform == 1) {
        var check = Drupal.checkAge();
      }
      // everything good, add cookie and close colorbox
      if (check) {
        $.cookie(settings.disclaimer.cookie_name, '1', { path: settings.disclaimer.cookie_path });
        $.colorbox.remove();
      }
    });
  },
};

}

    Drupal.checkAge = function () {
    var now = new Date();
    var date = now.getDate();
    var month = now.getMonth() + 1;
    var year = now.getFullYear();
    var optmonth = jQuery("#edit-disclaimer-age-month option:selected").val();
    var optday = jQuery("#edit-disclaimer-age-day option:selected").val();
    var optyear = jQuery("#edit-disclaimer-age-year option:selected").val();
    var age = year - optyear;
    if (optmonth > month) {age--;} else {if(optmonth == month && optday >= date) {age--;}}
    // if current year, form not set
    if (optyear == year) {
      alert(Drupal.t("You must enter the year you were born in."));
      return alert;
    // if under age, alert and redirect !
    } else if (age < Drupal.settings.disclaimer.limit) {
      alert(Drupal.t("Sorry, you are Under age limit and are prohibited from entering this site!"));
      location.replace(Drupal.settings.disclaimer.exiturl);
      return false;
    } else {
      // age limit ok
      return true;
    }
  }
4

2 に答える 2

8

あなたはalert を返しているからです。これにより、アラートが 2 回表示され、戻ってこないためfalse、次のページに進みます。

これを試して:

if (optyear == year) {
    alert(Drupal.t("You must enter the year you were born in."));
    return false;
}
于 2013-04-24T18:43:18.647 に答える
1

リターンアラートは必要ありません。

alert(Drupal.t("You must enter the year you were born in."));
//return alert;

アラートは、alert(); を使用するだけで発生します。

于 2013-04-24T18:43:32.550 に答える