htmlbuttonuibuttonbloggerblogger-dynamic-views

Blogger button link change after clicking it


In blogger, if the user click the button, it redirect to desired link. If the user click the same button for second time, I want to make the button to be redirected to another link. So how can I change the blogger button link to another link after clicking it?

I have searched and tried for two months. But I have no idea yet.


Solution

  • Please check below code for your question. here is some code idea that you can implement on your side.

    jQuery(document).ready(function ($) {
    
        // Secound URL Set For False
        var get_url = false;
    
        $('button').click(function (e) { 
            e.preventDefault();
            // Define URL
            var btn_url = $(this).data('url');
            var btn_url2 = $(this).data('url2');
    
            // First Url Execute
            if (get_url != true) {
                window.open(btn_url, '_blank');
                // First URL Clicked
                get_url = true;
            } 
            // Secound Url Execute
            else {
                window.open(btn_url2, '_blank');
            }
        });
    
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <button type="button" data-url="https://stackoverflow.com/" data-url2="google.com">Blogger BTN</button>