How to open links in new window ONLY IF the check box is checked

Posted by Travis on Stack Overflow See other posts from Stack Overflow or by Travis
Published on 2013-10-17T15:57:16Z Indexed on 2013/10/17 21:54 UTC
Read the original article Hit count: 225

Filed under:
|
|
|
|

Here is what i have so far. I have it so they open in new windows, but i want it only if the check box is checked...

<!DOCTYPE html>
<html>
<head>

<script>
    function new() {
       if ( document.getElementById('checkbox').checked )
            window.open( 'y', 'n', 't', 'New Window' );
    }
    else
    {
        break;
    }

    var OpenNew = document.getElementById('opennew');
    OpenNew.addEventListener('click', OpenWin, false );
</script>
</head>
<body>

<p>
<form name="test">
<p>Open link in a new window &nbsp; <input type="checkbox" id="checkbox" name="check" /></p>
</form>
</p>
<p>
<h2>My favorite Websites to visit</h2>
<a href="http://www.youtube.com" target="new" id="y">Youtube</a><br />
<a href="http://www.newegg.com" target="new" id="n">Newegg</a><br />
<a href="http://www.twitch.tv" target="new" id="t">Twitch.tv</a><br />
</p>












</body>

</html>

I am unsure how to actually do the if statement if it is checked then open. It does currently open in a new tab.. i just need it to be only when its checked.

Any help with this will be greatly appreciated! Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about html