当前位置:网站首页>JS基础7
JS基础7
2022-04-22 12:23:00 【鹏程933】
BOM
定义:浏览器对象模型
操作浏览器的能力
- 打开关闭浏览器
- 操作历史记录
- 滚动条
- 弹框
- 地址栏
Windows对象
打开浏览器窗口自动创建Windows对象
属性
| 属性 | 含义 |
|---|---|
| alert | 弹出提示框 |
| confirm | 显示提示信息,确定,取消 |
| prompt | 显示让用户输入内容框 |
| open | 打开一个新的浏览器,指定URL |
| close | 关闭浏览器 |
注:
- open接受4个参数:要加载的URL,目标窗口,特性字符串,新窗口在浏览器的历史记录是否替代当前加载页的布尔值
- alert,confirm,prompt的外观由浏览器决定,对话框显示时,代码会停止运行
计时器
- setTimeout()倒计时计数器
setTimeout(function(){
alert('')
},1000)
- setInterval()循环计时器
setInterval(function(){
alert('')
},1000)
- clearTimeout()终止循环
视屏
- innerHeight视屏高度
- innerWidth视屏宽度
- scrollTop距离视屏顶部距离
注:接受单位为PX - scrollLeft距离左边距离
- moveTo(x,y)移动到指定位置
- moveBy(x,y)移动到绝对坐标x,y
- resizeTo()调整窗口到指定大小
- resizeBy()调整指定大小
示例:过渡回到顶部
- 点击时获取当前高度
- 每100ms高度减100
- 赋值给scroollTop
- scroollTop小于等于0停止计数
<style> div{
height: 2000px;}
button{
position: fixed;
right: 50px;
bottom: 50px;
}
</style> <body> <div></div> <button οnclick="differtop()">回顶部</button> <script> function differtop(){
var windowheight=window.innerHeight;
//获取当前视屏高度/* */
var time=setInterval(function(){
//循环计时器
windowheight=windowheight-100;
//每次视屏高度减100
document.documentElement.scrollTop=windowheight; //视屏高度赋给距离顶部参数 if(document.documentElement.scrollTop<=0){
//判断如果距离顶部小于0则停止循环计时器
clearInterval(time)
}
},100)//100MS执行一次循环
}
</script>
history操作历史记录
- back()加载history对象列表前一个URL
- forward()加载history对象列表后一个URL
- go()加载history对象列表具体某一个URL
location操作地址栏
| 属性 | 含义 |
|---|---|
| href | 当前加载页面的完整URL |
| hash | #号后面的值 |
| host | 服务器名和端口名 |
| hostname | 服务器名 |
| pathname | URL中的路径和文件名 |
| port | 请求的端口 |
| protococol | 页面通用协议 |
| search | URL查询的字符串 |
| username | 域名前指定的用户名 |
| password | 域名前指定的密码 |
| origin | URL源地址(只读) |
navigator对象
- 定义:navigator对象是客户端标识浏览器的标准,只要启用JS,navigator对象就一定存在
注:通常用于确定浏览器的类型 - plugins数组确定浏览器是否安装了某个插件
| 属性 | 含义 |
|---|---|
| name | 插件名称 |
| description | 插件介绍 |
| filename | 插件的文件名 |
| length | 当前插件处理的MIME类型数量 |
<script> let hasPlugin=function(name){
name=name.toLowerCase(); for(let plugin of window.navigator.plugins){
if(plugin.name.toLocaleLowerCase().indexOf(name)>-1){
return true;
}
}
return false
}
//检测Flash QuickTime
alert(hasPlugin('Flash'))
alert(hasPlugin('QuickTime'))
</script>
版权声明
本文为[鹏程933]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_64925940/article/details/123597340
边栏推荐
- 【生活中的逻辑谬误】以暴制暴和压制理性
- What is the difference between CPU and GPU?
- Oracle Data Guard和金仓KingbaseES集群的数据保护模式对比
- Where have all the Internet people who left their jobs gone?
- 手机刷新率越高越好吗?
- Setting policy of thread pool size
- 机器学习 训练模板,汇总多个分类器
- 【深入理解TcaplusDB技术】扫描数据接口说明——[List表]
- 一种自动切换过流保护模块的热泵装置保护电路介绍(ACS758/CH704应用案例)
- [concurrent programming 053] Why use volatile variables for double check lock variables
猜你喜欢

前三个月免费试用!博睿数据告警平台OneAlert火热大促进行中
![[concurrent programming 052] talk about double check lock and its advantages?](/img/45/0d35b6b358f6605c46300f749dcd3d.png)
[concurrent programming 052] talk about double check lock and its advantages?
![[in depth understanding of tcallusdb technology] data interface description for reading the specified location in the list - [list table]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
[in depth understanding of tcallusdb technology] data interface description for reading the specified location in the list - [list table]
![[logical fallacies in life] controlling violence with violence and suppressing rationality](/img/5a/2d69a7ae6e2ac108cd2bd937f3fcdf.jpg)
[logical fallacies in life] controlling violence with violence and suppressing rationality

Codeforces Round #783 (Div. 2)
![[in depth understanding of tcallusdb technology] scan data interface description - [list table]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
[in depth understanding of tcallusdb technology] scan data interface description - [list table]
![【深入理解TcaplusDB技术】扫描数据接口说明——[List表]](/img/ed/cccd5dee09d2f0a3e6c788bd265b36.png)
【深入理解TcaplusDB技术】扫描数据接口说明——[List表]

低频(LF)RFID 智能终端

ORB_SLAM3学习:Tracking 线程介绍

Ner brief overview
随机推荐
[concurrent programming 051] implementation principle of volatile memory semantics
ThreadLocal
"Stack overflow Chinese content" is finally here! Invite you to experience feedback and get a good gift
What is the difference between CPU and GPU?
[deeply understand tcallusdb technology] delete all data interface descriptions in the list - [list table]
【并发编程050】内存屏障的种类以及说明?
Codeforces Round #783 (Div. 2)
电工第一讲
zuul使用中的一些问题
電工第二講
自动化测试的生命周期是什么?
电工第二讲
MySQL 5.0安装教程图解详细教程
LeetCode 206、反转链表
Heap overflow of kernel PWN basic tutorial
LeetCode 1678、设计 Goal 解析器
刷了一千道选择题,我总结了这些C语言易错点【第二弹】
NLP数据集整理(更新中)
MySQL学习第四弹——多表查询分类以及案例练习源码详解
UML总结