关于前端:windowlocationhref-和-windowopen-跳转的区别

10次阅读

共计 969 个字符,预计需要花费 3 分钟才能阅读完成。

一、间接跳转式:

window.location.href='https://www.baidu.com'

二、开新窗口跳转:

window.open(url, [name], [configuration])

*url:为要新关上页面的 url
*name:为新关上窗口的名字,能够通过此名字获取该窗口对象
*configuration:为新关上窗口的一些配置项,比方是否有菜单栏、滚动条、长低等等信息

例子:
新关上一个没有菜单栏、标题栏、工具栏,然而有滚动条、状态栏、地址栏且可伸缩窗口的办法调用如下:

window.open("index.html", "newWindow", "width=1024, height=700, top=0, left=0, titlebar=no, menubar=no, scrollbars=yes, resizable=yes, status=yes, , toolbar=no, location=yes");

1、参数解释
window.open 弹出新窗口的命令;
index.html 弹出窗口的文件名;
newWindow 弹出窗口的名字(不是文件名),非必须,可用空’’ 代替;
width=1024 窗口宽度;
height=700 窗口高度;
top=0 窗口间隔屏幕上方的象素值;
left=0 窗口间隔屏幕左侧的象素值;
titlebar=no 是否显示标题栏,被疏忽,除非调用 HTML 应用程序或一个值得信赖的对话框. 默认值是 yes;
menubar=no 示意菜单栏,默认值是 yes;
scrollbars=yes 是否显示滚动条,默认值是 yes;
resizable=no 是否容许扭转窗口大小,默认值是 yes;
status=no 是否要增加一个状态栏,默认值是 yes;
toolbar=no 是否显示工具栏,默认值是 yes;
location=no 是否显示地址栏,默认值是 yes;

2、window.open 关上新窗口还是关上新标签页
调用 window.open 是关上新窗口,还是关上新标签页,这里要加以辨别。

window.open(url)或者 window.open(url, name),其中 name 为_blank
规范浏览器、新标签关上链接 url

window.open(url, name, configration)
只有配置了 configration,都是新窗口关上链接的

正文完
 0