位置:- 正文

window.location.href的用法(window.location.href返回值)

编辑:rootadmin
window.location.href的用法

推荐整理分享window.location.href的用法(window.location.href返回值),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:window.location.href返回值,window.location.href下载文件异常,window.location.href返回值,window.location.href返回值,window.location.href跳转页面,window.location.href打开本地文件,window.location.href方法,window.location.href方法,内容如对您有帮助,希望把文章链接给更多的朋友!

javascript中的 location.href 有很多种用法,主要如下。

self.location.href=“/url” 当前页面打开URL页面

location.href=“/url” 当前页面打开URL页面

window.location.href=“/url” 当前页面打开URL页面,前面三个用法相同。

this.location.href=“/url” 当前页面打开URL页面

parent.location.href=“/url” 在父页面打开新页面

top.location.href=“/url” 在顶层页面打开新页面

如果页面中自定义了frame,那么可将parent self top换为自定义frame的名称,效果是在frame窗口打开url地址

此外,window.location.href=window.location.href;和window.location.Reload()和都是刷新当前页面。区别在于是否有提交数据。当有提交数据时,window.location.Reload()会提示是否提交,window.location.href=window.location.href;则是向指定的url提交数据

如果要关闭当前窗口,并且在新窗口打开某一链接:

var a = document.createElement('a')

a.setAttribute('href', href)

window.location.href的用法(window.location.href返回值)

a.setAttribute('target', '_blank')

a.setAttribute('id', 'startTelMedicine')

a.onclick = function () {

//关闭窗口的方法

window.opener = null

window.open('', '_self', '')

window.close()

}

// 防止反复添加

if (document.getElementById('startTelMedicine')) {

document.body.removeChild(document.getElementById('startTelMedicine'))

}

document.body.appendChild(a)

a.click()

如果无法关闭当前弹框 说明可能有父节点,可以试试:window.parent.close();

————————————————

版权

本文链接地址:https://www.jiuchutong.com/zhishi/293125.html 转载请保留说明!
下一篇链接:https://www.jiuchutong.com/zhishi/293126.html
免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络