组成:ECMAScript 语法、 bom 浏览器模型 与js 交互、dom 与html 内容交互
bom window :
browser object model : 浏览器对象模型
document:文档
screen:屏幕
screen.width、screen.height 屏幕宽高
screen.availwidth、screen.availheight 屏幕可用宽高
window.innerwidth、window.innerheight 屏幕可视宽高
代码如下
// document.write('<br> 屏幕宽' + screen.width)
// document.write('<br>屏幕高' + screen.height)
// document.write('<br>可用的' + screen.availWidth)
// document.write('<br> 可用的' + screen.availHeight)
// document.write('<br>看见的' + window.innerWidth)
// document.write('<br>看见的' + window.innerHeight)
history: 历史记录
history.forward 前进一个页面
history.back 后退一个页面
history.go(1)、(-1) 前进、后退
代码如下
// <button type="button" οnclick="go()">前进</button>
// <button type="button" οnclick="back()">后退</button> -->
// function go (){
// history.forward()
// history.go(1)
// }
// function back(){
// history.back()
// history.back(-1)
// }
location :地址栏 信息
location.href 地址信息
location.hostname 地址域名
location.protocol 地址协议
location.search 地址查询
location.pathname 地址路径
location.hash 哈希/锚点
location.port 地址端口
代码如下
// document.write('<br> 地址信息'+location.href)
// document.write('<br>域名'+location.hostname)
// document.write('<br>协议'+location.protocol)
// document.write('<br>查询'+location.search)
// document.write('<br>路径'+location.pathname)
// document.write('<br>哈希'+location.hash)
// document.write('<br>端口'+location.port)
ua=nacigator.userAgent:浏览器头信息
if(ua.includes(‘mobile’))判断是否是手机
代码如下
// 检测是否为手机
// var ua=navigator.userAgent;
// document.write('<br>'+ua)
// if(ua.includes('Mobile')){
// document.write('<br>手机')
// }else{
// document.write('<br>电脑')
// }
open 方法:
window.open(url,name,feature)
open 、close : 打开 新的浏览器 关闭当今浏览器
代码如下
// <!-- <button type="button" οnclick="opens()">打开</button>
// <button οnclick="closes()">关闭</button> -->
// function opens(){
// window.open("https://www.baidu.com")
// }
// function closes(){
// window.close()
// }
事件:
on scroll 滚动 事件
document.documentElement.scrollTop 滚动距离
onresize 窗口大小变化
代码如下:
// window.οnscrοll=function(){
// console.log('页面滚动')
// var t=document.documentElement.scrollTop
// console.log(t)
// }
字符串编码:
decode、encode
编译为url
decode url
encode url
转/解url编码
代码如下
// var str='中国'
// console.log(window.encodeURI(str))
// console.log(decodeURI(%E9%99%88%E5%9B%BD%E6%97%AD))
预览图片:
img.src=window.url.createobjecturl( my.files[0])
代码如下
// <input type="file" name="" id="tp" οnchange="preimg()">
// <img src="" width='50%'id='my'>
// function preimg(){
// var file=tp.file[0]
// var src=window.URL.createObjectURL(file[0])
// my.src=src
// }