浏览器
浏览器窗口的内部宽: window.innerWidth
浏览器窗口的内部高: window.innerHeight
内部宽高是指去除菜单栏、工具栏、边框等站位元素,用于显示网页的净宽高。
浏览器的整体宽高:
window.outerWidth、 window.outerHeight
navigator
navigator对象表示浏览器的信息,最常用的属性包括:
- navigator.appName:浏览器名称;
- navigator.appVersion:浏览器版本;
- navigator.language:浏览器设置的语言;
- navigator.platform:操作系统类型;
- navigator.userAgent:浏览器设定的
User-Agent字符串。
Screen
- screen.width: 屏幕宽度,以像素为单位
- screen.height: 屏幕高度
location
location对象表示当前页面的url信息,例如一个完整的url:
http://www.example.com:8080/path/index.html?a=1&b=2#TOP
location.protocol; // 'http' location.host; // 'www.example.com' location.port; // '8080' location.pathname; // '/path/index.html' location.search; // '?a=1&b=2' location.hash; // 'TOP'
加载一个新页面:
if (confirm('重新加载当前页' + location.href + '?')) { location.reload(); // 刷新当前页 } else { location.assign('/'); // 设置一个新的URL地址 }
document
document 对象还有一个cookie属性,可以获取当前页面的Cookie。
Cookie是由服务器发送的key-value标识符,因为HTTP是无状态的,但是服务器要区分到底是哪个用户发送过来的请求,就可以用Cookie区分。 当一个用户成功登录后,服务器发送一个Cookie给浏览器,此后,浏览器访问该网站时,会在请求头附上这个Cookie,服务器根据Cookie即可区分出用户。
js 可以通过 document.cookie 读取当前页面的Cookie:
浙公网安备 33010602011771号