努力したWiki

推敲の足りないメモ書き多数

ユーザ用ツール

サイト用ツール


documents:proglang:js:web-003

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
documents:proglang:js:web-003 [2026/05/12 23:01] – ↷ documents:proglang:web-003 から documents:proglang:js:web-003 へページを移動しました。 k896951documents:proglang:js:web-003 [2026/05/12 23:10] (現在) – [base64form] k896951
行 1: 行 1:
 +====== 003.BASE64 FORM ======
  
 +2026-04-29 日本語が通らなかったので修正実施。
 +===== フォーム =====
 +
 +定義したutf8_to_b64()でBASE64エンコード、b64_to_utf8()でBASE64デコードするフォーム。
 +
 +<html>
 +    <textarea id="txt" rows="5" cols="40" placeholder="ここにテキストを貼ってください"></textarea><br/>
 +    <button id="dec">utf8_to_b64()</button>&nbsp;<button id="enc">b64_to_utf8()</button>
 +    <script>
 +      function utf8_to_b64(str) {
 +          return btoa(unescape(encodeURIComponent(str)));
 +      }
 +
 +      function b64_to_utf8(b64) {
 +          return decodeURIComponent(escape(atob(b64)));
 +      }
 +      document.getElementById('dec').addEventListener('click',function(e){ document.getElementById('txt').value=utf8_to_b64(document.getElementById('txt').value)});
 +      document.getElementById('enc').addEventListener('click',function(e){ document.getElementById('txt').value=b64_to_utf8(document.getElementById('txt').value)});
 +    </script>
 +</html>
 +
 +===== HTML =====
 +
 +デスクトップにファイルを置いてダブルクリックで使えるようにしておくといいかも。
 +<code html decenc.html>
 +<!doctype html>
 +<html>
 +  <head>
 +    <title>base64 decode encode</title>
 +  </head>
 +  <body>
 +    <h1>base64 decode encode</h1>
 +    定義したutf8_to_b64()でBASE64エンコード、b64_to_utf8()でBASE64デコードするフォーム。 <br/>
 +    <textarea id="txt" rows="5" cols="40" placeholder="ここにテキストを貼ってください"></textarea><br/>
 +    <button id="dec">utf8_to_b64()</button>&nbsp;<button id="enc">b64_to_utf8()</button>
 +    <script>
 +      function utf8_to_b64(str) {
 +          return btoa(unescape(encodeURIComponent(str)));
 +      }
 +
 +      function b64_to_utf8(b64) {
 +          return decodeURIComponent(escape(atob(b64)));
 +      }
 +      document.getElementById('dec').addEventListener('click',function(e){ document.getElementById('txt').value=utf8_to_b64(document.getElementById('txt').value)});
 +      document.getElementById('enc').addEventListener('click',function(e){ document.getElementById('txt').value=b64_to_utf8(document.getElementById('txt').value)});
 +    </script>
 +  </body>
 +</html>
 +</code>
 +{{tag>JavaScript エンコードフォーム デコードフォーム}}
documents/proglang/js/web-003.txt · 最終更新: by k896951

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki