JS打开url的几种方法

时间:2019-12-19
本文章向大家介绍JS打开url的几种方法,主要包括JS打开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); //同步

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可以在一个网站上打开另外的一个网站的地址 。

原文地址:https://www.cnblogs.com/aeolian/p/12066730.html