お問い合わせフォーム

名前

電話パターン1(親要素のidとマッチ)

<div id=html-tel>
<a href="tel:000-1234-5678">htmltel:000-1234-5678</a>
</div>

電話パターン2(自分のidとマッチ)

htmltel:999-8765-4321
<a href="tel:000-1234-5678" id="html-tel2">htmltel:999-8765-4321</a>

電話パターン

<div id="js-tel">
<button id="test-tel-btn" style="padding: 10px 20px; font-weight: bold; cursor: pointer;">
    📞 【JSテスト】03-1234-5678 に電話する
</button>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // 1. ボタン要素を取得
    var telBtn = document.getElementById('test-tel-btn');
    
    // 2. ボタンが存在する場合のみ処理を実行
    if (telBtn) {
        telBtn.addEventListener('click', function() {
            // スマホ判定
            var ua = navigator.userAgent.toLowerCase();
            var isMobile = /iphone/.test(ua) || /android(.+)?mobile/.test(ua);
            
            if (isMobile) {
                // スマホの場合:JavaScriptから動的に電話を発信
                window.location.href = 'tel:0312345678';
            } else {
                // PCの場合:発信せずにテスト用のアラートを出す
                alert('【JSテスト動作】スマホ環境ではないため、発信処理(window.location.href)をスキップしました。');
            }
        });
    }
});
</script>

電話パターン4

<div id="js-tel2">
<button id="test-tel-btn" style="padding: 10px 20px; font-weight: bold; cursor: pointer;">
    📞 【JSテスト】03-1234-5678 に電話する
</button>
</div>

<script>
document.addEventListener('DOMContentLoaded', function() {
    // 1. ボタン要素を取得
    var telBtn = document.getElementById('test-tel-btn');
    
    // 2. ボタンが存在する場合のみ処理を実行
    if (telBtn) {
        telBtn.addEventListener('click', function() {
            // スマホ判定
            var ua = navigator.userAgent.toLowerCase();
            var isMobile = /iphone/.test(ua) || /android(.+)?mobile/.test(ua);
            
            if (isMobile) {
                // スマホの場合:JavaScriptから動的に電話を発信
                window.location.href = 'tel:0312345678';
            } else {
                // PCの場合:発信せずにテスト用のアラートを出す
                alert('【JSテスト動作】スマホ環境ではないため、発信処理(window.location.href)をスキップしました。');
            }
        });
    }
});
</script>