溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

簡(jiǎn)單了解JS打開(kāi)url的方法

發(fā)布時(shí)間:2020-09-25 08:10:46 來(lái)源:腳本之家 閱讀:423 作者:秋夜雨巷 欄目:web開(kāi)發(fā)

這篇文章主要介紹了簡(jiǎn)單了解JS打開(kāi)url的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

在新標(biāo)簽頁(yè)中g(shù)et方式打開(kāi)url

window.open(loginurl_withaccout, "_blank");

下面根據(jù)后臺(tái)返回的url以及用戶(hù)名密碼字段,以及用戶(hù)名密碼動(dòng)態(tài)生成了帶賬號(hào)的url。

$.ax('./front/getURLBySidAndUid', {sysid:sysid}, 'POST', function(d) {
  var loginurl_withaccout = d.loginurl + "?"+d.namefield+"="+d.username+"&"+d.pwdfield+"="+d.userpwd;
  console.info(loginurl_withaccout);
  window.open(loginurl_withaccout, "_blank");
}, function(e) {
  layer.alert('出問(wèn)題啦~請(qǐng)稍后再試~',{title:'提示',icon: 2});
}, false); //同步

在新標(biāo)簽頁(yè)中post方式打開(kāi)url

下面這種方式支持IE9以上以及谷歌火狐.但是不支持360

/*獲取系統(tǒng)帶參數(shù)的登錄url*/
$.ax('./front/getURLBySidAndUid', {sysid:sysid}, 'POST', function(d) {

  /*get跳轉(zhuǎn)*/
  /*var loginurl_withaccout = d.loginurl + "?"+d.namefield+"="+d.username+"&"+d.pwdfield+"="+d.userpwd;
  window.open(loginurl_withaccout, "_blank");*/

  /*post跳轉(zhuǎn)*/
  var params = new Array();
  params.push({ name:d.namefield,value:d.username},{name:d.pwdfield,value:d.userpwd});
  openPostWindow(d.loginurl,params,"_blank");
}, function(e) {
  layer.alert('出問(wèn)題啦~請(qǐng)稍后再試~',{title:'提示',icon: 2});
}, false); //同步

  /**
   * 動(dòng)態(tài)創(chuàng)建form表單 - 實(shí)現(xiàn)post帶參數(shù)跳轉(zhuǎn)到新tab頁(yè)
   **/
  function openPostWindow(url,params,name){
    var tempForm = document.createElement("form");
    tempForm.id="tempForm_post";
    tempForm.method="post";
    tempForm.enctype="application/x-www-form-urlencoded";
    tempForm.action=url;
    tempForm.target=name; /*打開(kāi)新窗口*/
    tempForm.style.display = "none";
    //添加參數(shù)
    for (var item in params) {
      var input = document.createElement("input");
      input.name = params[item].name;
      input.value = params[item].value;
      tempForm.appendChild(input);
    }
    document.body.appendChild(tempForm);
    tempForm.submit();
    document.body.removeChild(tempForm);
  }

window.location和window.open區(qū)別

性質(zhì)不同

  • window.location:window.location是window對(duì)象的屬性。
  • window.open:window.open是window對(duì)象的方法。

用途不同

  • window.location:window.location用來(lái)替換當(dāng)前頁(yè),也就是重新定位當(dāng)前頁(yè) 。
  • window.open:window.open用來(lái)讓鏈接頁(yè)面在窗口中打開(kāi)。

打開(kāi)網(wǎng)站不同

  • window.location:window.location只能在一個(gè)網(wǎng)站中打開(kāi)本網(wǎng)站的網(wǎng)頁(yè)。
  • window.open:window.open可以在一個(gè)網(wǎng)站上打開(kāi)另外的一個(gè)網(wǎng)站的地址 。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持億速云。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI