2015-11-06 71 views
0

下面的代碼將在引導模式出現之前首先打開新選項卡。在新選項卡之前,是否有引導模式首先打開的方式?有沒有一種方法可以在新選項卡打開之前引導程序模式首先打開?

$(document).on("click", ".listings", function() { 
    var id = $(this).attr("id"); 

    $.ajax({ 
     url: "http://api.myjson.com/bins/2sadq?pretty=1", 
     dataType: "json", 
     success: function(response) { 

      var modal = "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'><div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header'><button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button><h4 class='modal-title' id='myModalLabel'>Aloha!</h4></div><div class='modal-body'>Apartment address through Google Maps. Epic! Right?</div><div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button></div></div></div></div>"; 
      $('#myModal').modal('show'); 
      $(".modals").append(modal); 

      var selectedApartment = $.grep(response.apartments, function(apartment) { 
       return apartment.id == id; 
      }); 

      var address = selectedApartment[0].address; 

      window.open("http://maps.google.com/?q=" + address); 
     }, 

     error: function(error) { 
      console.log(error); 
     } 

    }); 
}); 

此外,如果你想看看完整的項目文件,這裏是保管箱鏈接。

Full project file dropbox link

回答

0

你也可以的setTimeout拖延開彈出:

setTimeout(function() {window.open("http://maps.google.com/?q=" + address)}, 1000); 

更新:如果你想要的彈出窗口點擊關閉按鈕後:

success: function(response) { 

       var modal = "<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel'><div class='modal-dialog' role='document'><div class='modal-content'><div class='modal-header'><button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button><h4 class='modal-title' id='myModalLabel'>Aloha!</h4></div><div class='modal-body'>Apartment address through Google Maps. Epic! Right?</div><div class='modal-footer'><button type='button' class='btn btn-default' data-dismiss='modal'>Close</button></div></div></div></div>"; 

       $(".modals").html(modal); 

       var selectedApartment = $.grep(response.apartments, function(apartment) { 
        return apartment.id == id; 
       }); 

       var address = selectedApartment[0].address; 

       $('#myModal').on('hide.bs.modal', function (e) { 
        window.open("http://maps.google.com/?q=" + address); 
       }); 
       $('#myModal').modal('show'); 
      }, 
+0

這作品。我只是想知道,如果我點擊模式上的關閉按鈕,新選項卡是否可能會打開? –

+0

我只注意到模式在第一次通話或點擊時不起作用。爲什麼? –

+0

現在有效。看到我上面的更新。 –

相關問題