前提
GASでフォームを作成した後にjquery.cookie.jsを使用し、Cookieにフォーム内容を保存することを最終目標としています。
現在その前段階で、そもそもjquery.cookie.jsをGASで使用できるのかという試し段階で躓いております。
伺いたいのは下記の通りです。
- そもそも、GASでjquery.cookie.jsは使用できるのか
- できる→下記のコードでなにかしらの間違いがあるのでしょうか。
基本的な質問で申し訳ございませんが、アドバイスいただければ幸いです。
発生している問題・エラーメッセージ
ボタンを押しても何も反応しません。
実際のコード
jquery.cookie.jsを試す目的で下記作成しました。
結果はリロードするとカウントが0に戻ってしまうため、Cookieへの保存がうまく行っていない状況です。
参考サイト:https://webdesignday.jp/inspiration/technique/jquery-js/3704/
HTML&jQuery
1<!DOCTYPE html> 2<html lang="ja"> 3<head> 4<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 5<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script> 6</head> 7<body> 8 9 10<p>「カウントアップ」クリックでカウントアップし、ブラウザを終了しない限り値を維持します。<br> 11「リセット」クリックでcookieを削除します。</p> 12<p>カウント:<span class="js-count-num"></span></p> 13<button class="js-count-btn">カウントアップ</button><button class="js-reset-btn">リセット</button> 14 15<script type="text/javascript"> 16var cookie = $.cookie('cookie'); 17if(cookie){ 18 $('.js-count-num').text(cookie); 19} 20else{ 21 $('.js-count-num').text(0); 22} 23var count = $('.js-count-num').text(); 24$('.js-count-btn').on('click',function(){ 25 count++; 26 $.cookie( "cookie",count,{expires:7}); 27 $('.js-count-num').text(count); 28}); 29$('.js-reset-btn').on('click',function(){ 30 count = 0; 31 $.removeCookie( "cookie"); 32 $('.js-count-num').text(count); 33}); 34</script> 35</body> 36</html>
GAS
1function doGet(e){ 2 const template = HtmlService.createTemplateFromFile('index'); 3 const output = template.evaluate(); 4 output.setTitle('CookieTEST'); 5 output.addMetaTag('viewport', 'width=device-width, initial-scale=1,user-scalable=no') 6 return output; 7 8}

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/07/25 07:51
2022/07/25 08:07
2022/07/25 08:11