Visit selected link on button

前端 未结 2 376
时光取名叫无心
时光取名叫无心 2021-01-29 17:07

How can I visit a selected link from drop-down list on external button in a new window?


                        
    
提交评论

  • 2021-01-29 17:25

    I am supposing here you want select the site and want to open that site after click on downlad button.

    HTML

    <select id="select">
        <option value="http://google.com">google</option>
        <option value="http://yahoo.com">yahoo</option>
    </select>
    <button id="myButton">Download</button>
    

    JS

    var button = document.getElementById("myButton");
    button.addEventListener("click", function() { 
        var select = document.getElementById('select');
        var win = window.open(select.options[select.selectedIndex].value, "_blank");
        win.focus();
    
    },false);
    

    DEMO

    0 讨论(0)
  • 提交回复
    热议问题