skip to Main Content

please anybody help me thru this case 🙁
I just started learning html css and javascript, and i have a problem. I need to make the visitor to open an extra tab with specific url after clicking a button. This specific url is actually a thankyou page, so that after they finished filling out a form and click hte button ‘Register’, they dont just got redirected to a new page, but also open an extra tab.
the button inside the body tag is declared in this code:

<input type="button" class="btn btn-masuk fw-bold" value="Daftar" style="margin-top:20px; width:200px; text-align: center; display: grid; place-items: center; line-height: var(--text-size-default); height: 40px" id="buttonRegister">    

Now, the original script works fine but I dont know how to make the auto open extra tab after clicking that button, plus i cannot edit anything inside the body tag since its a template cms, including the button code itself, i can only add some script at the footer text or head meta.
i dont know if I should add an extra javascript code or else to make this works, please help

2

Answers


  1. Try this one

     <button class="btn btn-success" onclick=" window.open('http://google.com','_blank')"> Google</button>
    
    Login or Signup to reply.
  2. If you’re unable to modify the HTML directly but can add script tags to the footer or head meta, you can use JavaScript to attach a click event listener to the button and open a new tab when it is clicked. Here’s an example script you can add to the footer or head meta

    document.addEventListener("DOMContentLoaded", function() {
    var registerButton = document.getElementById("buttonRegister");
    
    if (registerButton) {
        registerButton.addEventListener("click", function() {
            var thankYouPageUrl = "https://example.com/thankyou";
            window.open(thankYouPageUrl, '_blank');
        });
    }
    

    });

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search