重定向到浏览器中没有弹出菜单的链接

时间:2019-04-21 16:21:35

标签: javascript html bootstrap-4

我有两个带有“提交”按钮的下拉菜单,可根据下拉菜单中的选择将访问者重定向到特定的网址。

问题:访问者单击“提交”按钮时,浏览器向他显示一个弹出菜单,如下面的屏幕快照所示。我需要禁用此弹出窗口。这意味着访问者应该平稳,直接地进入目标网址。

screenshot

HTML

<form>
  <select id="carbrand">
    <option value="volvo">Volvo</option>
    <option value="saab" selected="selected">Saab</option>
    <option value="opel">Opel</option>
    <option value="audi">Audi</option>
  </select>

  <select id="carcolor">
    <option value="white">White</option>
    <option value="black" selected="selected">Black</option>
    <option value="red">Red</option>
    <option value="blue">Blue</option>
  </select>

  <br/><br/>

  <input id="btnCallURL" type="button" value="Call URL">  
</form>

JavaScript



<script>

document.getElementById('btnCallURL').onclick = function() { 
    var carbrandObj = document.getElementById('carbrand');
    var carcolorObj = document.getElementById('carcolor');

    var carbrandValue = carbrandObj.options[carbrandObj.selectedIndex].value;
    var carColorValue = carcolorObj.options[carcolorObj.selectedIndex].value;

    jsCallUrl(carbrandValue, carColorValue);
}

function jsCallUrl(carbrandValue, carColorValue){

    var pageUrl = "";

    switch (carbrandValue){
        case "volvo":
            switch (carColorValue){
            case "white":
                pageUrl = "volvo-white-page-url.php";
                break;
            case "black":
                pageUrl = "volvo-black-page-url.php";
                break;
            default:
                pageUrl = "volvo-othercolor-page-url.php";
                break;
          }
          break;
        case "saab":
            switch (carColorValue){
            case "white":
                pageUrl = "saab-white-page-url.php";
                break;
            case "black":
                pageUrl = "saab-black-page-url.php";
                break;
            default:
                pageUrl = "saab-othercolor-page-url.php";
                break;
          }
          break;
    }

    alert(pageUrl);

    if (pageUrl != ""){
      location.href = "https://domain/" + pageUrl;
    }
}

</script>

1 个答案:

答案 0 :(得分:3)

删除代码的这一部分:

alert(pageUrl);

Window alert() Method