web建站教程
  1. 首页
  2. vuejs
  3. js
  4. 好玩
  5. AIGC工具
  6. 前端知识
  7. 百度echarts
  8. 更多
    php入门
    nodejs
    mockjs
    reactjs
    mysql
    wordpress
    织梦cms
    帝国cms
    git教程
    IT知识
    模板大全
    休息站
    手机应用

新手入门:window.location的对象属性的基本用法

476 ℃

具体语法如下:

console.log(window.location.href);       // https://ipkd.cn/path?id=123#section
console.log(window.location.protocol);   // https:
console.log(window.location.host);       // ipkd.cn
console.log(window.location.hostname);   // ipkd.cn
console.log(window.location.port);       // (空字符串)
console.log(window.location.pathname);   // /path
console.log(window.location.search);     // ?id=123
console.log(window.location.hash);       // #section

参数介绍:

1、`window.location.href`:包含完整的URL,可以读取或设置该属性来导航到新的URL。
2、`window.location.protocol`:包含当前URL的协议部分(例如`http:`、`https:`)。
3、`window.location.host`:包含当前URL的主机名称和端口号。
4、`window.location.hostname`:包含当前URL的主机名称。
5、`window.location.port`:包含当前URL的端口号。
6、`window.location.pathname`:包含当前URL的路径部分。
7、`window.location.search`:包含当前URL的查询字符串部分(即URL中位于问号后面的部分)。
8、`window.location.hash`:包含当前URL的锚点部分(即URL中位于井号后面的部分)。

js刷新当前页面的4种方法

关于window.location的各种属性介绍

标签: window.location

上面是“新手入门:window.location的对象属性的基本用法”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。

当前网址:https://ipkd.cn/webs_5131.html

声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

当前位置: 网站首页 > js
本文共计787个字,预计阅读时长6分钟
生活小工具,收录了80多款小工具
上一篇: 推荐一款免费开源的屏幕录制软件——OBS Studio
下一篇: 推荐一个高质量的图片素材网站——Unsplash
x 打工人ai神器