Using html button + javascript function to open links in new window


Hi all,

Im trying to set up a function where once a html button is pressed, a function checks a variable and redirects a link to a new window if the value comes back positive.

This is the function I’m trying to get going:

     function launchTask()   

and the button

button type=“button” onclick=“LaunchTask()”

Theres probably a basic solution i’m not seeing, can somebody help?


The first thing to check is that the browser isn’t preventing popup windows (which would most likely open in a new tab, anyway.)

Use DevTools (F12) and click on the “Console” tab. Click your button. If there are any JavaScript issues, there should be a warning appear.


^ _ ^

UPDATE: Oh, and don’t use _blank as the window name. Use something else.


You’ll see the error if you open the console of your dev tools – you misspelled the function name, it starts lowercased. Better though would be to avoid inline-JS altogether; your code gets much easier to debug if you have your logic separate from the markup:


<button type="button" id="redirect">redirect</button>


var redirectBtn = document.getElementById('redirect')

redirectBtn.addEventListener('click', function launchTask () {'...')



I completely flaked on that. Did not see it at all. Good eye.


^ _ ^