1

MobileMe でホストされていない iweb ページでこれを機能させようとしています。以下のコードを使用すると、セッションごとに 1 回ではなく、ページを更新するたびにアラート ボックスが引き続き表示されます。私はここでまったくの初心者ですので、親切にしてください。

//Alert message once script- By JavaScript Kit
//Credit notice must stay intact for use
//Visit http://javascriptkit.com for this script

//specify message to alert
var answer=confirm("Click OK if you have been cleared Sutter's HR department to start       
volunteering.")
if (answer)
 alert ("Excellent!!  Please select your dates directly within the scheduling calendar.")
else
 alert ("Let's get to it then. Contact Ruth in HR at 576-4208 to schedule an appointment     so you can get started.")


///No editing required beyond here/////

//answer only once per browser session (0=no, 1=yes)
var once_per_session=1


function get_cookie(Name) {
  var search = Name + "="
  var returnvalue = "";
  if (document.cookie.length > 0) {
    offset = document.cookie.indexOf(search)
    if (offset != -1) { // if cookie exists
      offset += search.length
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
         end = document.cookie.length;
      returnvalue=unescape(document.cookie.substring(offset, end))
      }
   }
  return returnvalue;
}

function alertornot(){
if (get_cookie('alerted')==''){
loadalert()
document.cookie="alerted=yes"
}
}

function loadalert(){
alert(alertmessage)
}

if (once_per_session==0)
loadalert()
else
alertornot()

</script>
4

1 に答える 1

2

コードはこれをセッションごとに 1 回呼び出します。

alert(alertmessage)

ただし、一番上のコードはスクリプトのロードごとに呼び出されます。

さらに、 が定義されている場所がわかりません...したがって、おそらくコードを関数alertmessage内に上から配置すると、次のようになります。loadalert

function loadalert(){
var answer=confirm("Click OK if you have been cleared Sutter's HR department to start  volunteering.")
if (answer)
 alert ("Excellent!!  Please select your dates directly within the scheduling calendar.")
else
 alert ("Let's get to it then. Contact Ruth in HR at 576-4208 to schedule an appointment     so you can get started.")

}

編集:

そしてところで - 中括弧の使用を開始します。デバッグや、あなたがどこにいるかを理解するのに役立ちます。:)

于 2010-05-19T18:01:13.387 に答える