簡單了解JS打開url的方法
這篇文章主要介紹了簡單了解JS打開url的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
在新標(biāo)簽頁中g(shù)et方式打開url
window.open(loginurl_withaccout, "_blank");
下面根據(jù)后臺返回的url以及用戶名密碼字段,以及用戶名密碼動態(tài)生成了帶賬號的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('出問題啦~請稍后再試~',{title:'提示',icon: 2});
}, false); //同步
在新標(biāo)簽頁中post方式打開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('出問題啦~請稍后再試~',{title:'提示',icon: 2});
}, false); //同步
/**
* 動態(tài)創(chuàng)建form表單 - 實(shí)現(xiàn)post帶參數(shù)跳轉(zhuǎn)到新tab頁
**/
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; /*打開新窗口*/
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對象的屬性。
- window.open:window.open是window對象的方法。
用途不同
- window.location:window.location用來替換當(dāng)前頁,也就是重新定位當(dāng)前頁 。
- window.open:window.open用來讓鏈接頁面在窗口中打開。
打開網(wǎng)站不同
- window.location:window.location只能在一個網(wǎng)站中打開本網(wǎng)站的網(wǎng)頁。
- window.open:window.open可以在一個網(wǎng)站上打開另外的一個網(wǎng)站的地址 。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JsRender for index循環(huán)索引用法詳解
這篇文章主要介紹了JsRender for index循環(huán)索引用法,以實(shí)例形式詳細(xì)分析了JsRender中循環(huán)的用法,需要的朋友可以參考下2014-10-10
javascript實(shí)現(xiàn)仿銀行密碼輸入框效果的代碼
這篇文章通過實(shí)例代碼給大家介紹了javascript實(shí)現(xiàn)仿銀行密碼輸入框效果,代碼簡單易懂,非常不錯,具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2007-12-12
Uniapp?實(shí)現(xiàn)全民分銷功能原理解析
這篇文章主要介紹了Uniapp?實(shí)現(xiàn)全民分銷功能,本篇文章主要介紹全民分銷功能實(shí)現(xiàn)原理,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06
JS構(gòu)建頁面的DOM節(jié)點(diǎn)結(jié)構(gòu)的實(shí)現(xiàn)代碼
本來想用json格式的,可是要么有重復(fù),要么得嵌套,所以改用對象嵌套數(shù)組2011-12-12
原生javascript實(shí)現(xiàn)Tab選項(xiàng)卡切換功能
本文主要介紹了使用原生javascript實(shí)現(xiàn)Tab選項(xiàng)卡切換的功能,雖然jQuery有很多類似的插件,單jQuery庫著實(shí)有點(diǎn)龐大,這種小功能還是直接用javascript來做就好了。2015-01-01
微信小程序非跳轉(zhuǎn)式組件授權(quán)登錄的方法示例
這篇文章主要介紹了微信小程序非跳轉(zhuǎn)式組件授權(quán)登錄的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05

