简单了解JS打开url的⽅法
这篇⽂章主要介绍了简单了解JS打开url的⽅法,⽂中通过⽰例代码介绍的⾮常详细,对⼤家的学习或者⼯作具有⼀定的参考学习价值,需要的朋友可以参考下
在新标签页中get⽅式打开url
window.open(loginurl_withaccout, "_blank");
下⾯根据后台返回的url以及⽤户名密码字段,以及⽤户名密码动态⽣成了带账号的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); //同步
在新标签页中post⽅式打开url
下⾯这种⽅式⽀持IE9以上以及⾕歌⽕狐.但是不⽀持360
/*获取系统带参数的登录url*/
$.ax('./front/getURLBySidAndUid', {sysid:sysid}, 'POST', function(d) {
/*get跳转*/
/*var loginurl_withaccout = d.loginurl + "?"+d.namefield+"="+d.username+"&"+d.pwdfield+"="+d.userpwd;
window.open(loginurl_withaccout, "_blank");*/
/*post跳转*/
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); //同步
/**
* 动态创建form表单 - 实现post带参数跳转到新tab页
**/
function openPostWindow(url,params,name){
var tempForm = ateElement("form");
tempForm.id="tempForm_post";
tempForm.action=url;
tempForm.target=name; /*打开新窗⼝*/
tempForm.style.display = "none";
//添加参数
for (var item in params) {
var input = ateElement("input");js教程removechild
input.name = params[item].name;
input.value = params[item].value;
tempForm.appendChild(input);
}
document.body.appendChild(tempForm);
tempForm.submit();
veChild(tempForm);
}
window.location和window.open区别
性质不同
window.location:window.location是window对象的属性。
window.open:window.open是window对象的⽅法。
⽤途不同
window.location:window.location⽤来替换当前页,也就是重新定位当前页。
window.open:window.open⽤来让链接页⾯在窗⼝中打开。
打开⽹站不同
window.location:window.location只能在⼀个⽹站中打开本⽹站的⽹页。
window.open:window.open可以在⼀个⽹站上打开另外的⼀个⽹站的地址。以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。