首页 >> js开发 >> js简单了解JS打开url的方法js大全
js简单了解JS打开url的方法js大全
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
这篇文章主要介绍了简单了解JS打开url的方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下在新标签页中get方式打开url
window.open(loginurl_withaccout, "_blank");
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); //同步
$.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 = 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";
//添加参数
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);
}
/*获取系统带参数的登录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 = 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";
//添加参数
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区别
性质不同
window.location:window.location是window对象的属性。
window.open:window.open是window对象的方法。
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用来让链接页面在窗口中打开。打开网站不同
window.location:window.location只能在一个网站中打开本网站的网页。
window.open:window.open可以在一个网站上打开另外的一个网站的地址 。
window.location:window.location只能在一个网站中打开本网站的网页。window.open:window.open可以在一个网站上打开另外的一个网站的地址 。以上就是本文的全部内容,希望对大家的学习有所帮助。
window.open(loginurl_withaccout, "_blank");
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); //同步
$.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 = 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";
//添加参数
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);
}
/*获取系统带参数的登录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 = 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";
//添加参数
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区别
性质不同
window.location:window.location是window对象的属性。
window.open:window.open是window对象的方法。
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用来让链接页面在窗口中打开。打开网站不同
window.location:window.location只能在一个网站中打开本网站的网页。
window.open:window.open可以在一个网站上打开另外的一个网站的地址 。
window.location:window.location只能在一个网站中打开本网站的网页。window.open:window.open可以在一个网站上打开另外的一个网站的地址 。以上就是本文的全部内容,希望对大家的学习有所帮助。