0
0

ボタンを押した時だけheadタグにscriptタグを追加する

Last updated at Posted at 2024-01-12

<button type="submit" name="sending" id="addCustomCodeBtn">
    headタグに追加する
</button>

<script>
    document.getElementById('addCustomCodeBtn').addEventListener('click', function () {
        // 新しいスクリプト要素を作成
        var newScript = document.createElement('script');

        // スクリプトの内容を設定
        newScript.textContent = ` 入れたい内容(scriptタグはいらない) `;

        // <head>内に新しいスクリプト要素を挿入
        document.head.appendChild(newScript);
    });
</script>


0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0