如何open一個新tab頁面


打開新tab頁的兩種方式

1 a標簽

  function openwin(url) {
    var a = document.createElement("a");
    a.setAttribute("href", url);
     a.setAttribute("target", "_blank");
     a.setAttribute("id", "camnpr");
     document.body.appendChild(a);
     a.click();
  }

2 window.open

window.open('https://sandbox.ebanx.com/print/?hash=59ad5dd18a6d5ba0e24327c2ba92a730115a80bd58b3baa5', '_blank')

有3種情況會需要打開新tab頁,

  • 人為點擊一個按鈕,在事件里我們可以打開新的tab頁,window。open()
  • 用戶直接點擊a標簽打開新tab頁
  • 用戶觸法的ajax回調,在回調事件里才能拿到新的需要跳轉的tab頁的url,此時以上方法打開新頁面時候回被chrome等游覽器默認攔截

解決方案:

function click() {

	var newWin = window.open('loadingurl');
      $.ajax({
          url: url,
          type: "post",
          data: payParams,
          dataType: 'json',
          success: function (response) {
            newWin.location = response.data.url
		}
	})

}

就是在點擊的時候 先打開一個默認的loading頁面 然后在等url回來后在賦值給location

以上


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM