vendredi 30 mars 2018

how to open link in external window with click on anchor tag with javascript?

This is probably such a noob question, but i can't get it to work.

I want to open external window link by clicking on anchor tag, but i keep getting error that myFunction() is not defined.

<a href="#" id="searchEng" onclick="myFunction()">Open link</a>

js

$(document).ready(function(){ 
$('#searchEng').click(function() {
    const engine = document.getElementById('engine');
    var en_ = engine.val();
    if (en_ == "firefox")
    {
        function myFunction(){
                var url = "https://www.mozilla.org/en-US/firefox/new/";
                window.open(url,'_blank');
            };
    }
});

));

Why is it undefined?

I have .js included because other stuff works.

Thanks :)




Aucun commentaire:

Enregistrer un commentaire