ユーザーが連絡先フォームを送信した Web サイトを特定したいと考えています。
お問い合わせフォームはインクルード ファイル (.shtml) であり、このファイルは 2 つの異なる Web サイトで使用されています。それは1つのファイル(インクルード)だけなので、javascriptif...else
ステートメントまたはswitch
ステートメントでこれを行いますか? もしそうなら、それはどのように書かれますか?
私は JavaScript が初めてで、あまり書く必要がなかったので、構文の助けをいただければ幸いです。
2 つの異なるサイトの ID を使用して、1 つのインクルード コンタクト フォームに 2 つの非表示フィールドを追加することを考えました。
html
<input type="hidden" data-id="new_student_signup" name="student_signup" value="" />
<input type="hidden" data-id="existing_student_signup" name="existing_student_signup" value="" />
js
if(data-id="new_student_signup"){
// this user came from the new student website
code if this condition is true
}
else if(data-id="existing_student_signup"){
// this user came from the existing student website
code if this condition is true
}
または、1 つのインクルードで JavaScript を使用する代わりに、他の Web サイト用の新しいインクルード ファイルを作成し、そのファイルに隠しフィールドを追加する必要がありますか?
確かに、私のような JavaScript の初心者にとってはそれが最も簡単なように思えますが、JavaScript をもっと学ぶという考えは気に入っています。