走进javascript(七)

时间:2020-04-13
本文章向大家介绍走进javascript(七),主要包括走进javascript(七)使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

BOM

Window

所有全局定义的变量和函数都挂载在window全局对象峡; 可直接通过window.prop访问

var c = dd; 
异常抛错, dd未定义

var c = window.dd; 
当无法判断的时候通过这种方式来实现可以避免这种错误

top , parent , self
window.top 
window.parent   
window.self 

top: 始终指向最顶层的window
parent:当前框架的上级框架
self: 当前框架

窗口位置
screenLeft,screenTop,screenX,screenY

窗口大小
innerHeight,innerWidth
outerHeight,outerWidth
document.documentElement.clientWidth,clientHeight
document.body.clientWidth,clientHeight

新建窗口
window.open(url, target, 一个特性字符串,replace[浏览器历史记录条目是否替换]);

target
:_self, _parent, _top, _black

var timeoutId = setTimeout(func, ms) 等待一定时间后,将函数放入待执行的队列中,
如果队列为空,立即执行,否则等待队列中清空后,在执行
clearTimeout(timeoutId); //清除待执行任务

var intervalId = setInterval(function, ms) 每隔固定时间将函数移入待执行队列中执行
clearIntervalId(intervalId); 清除掉定时任务销毁

对话框
alert prompt comfirm

location

window.location = document.location

常用属性

hash  返回URL中的hash(#号后跟0或多个字符), 若无,则为空字符串
host 服务器名称+port
hostname host不包含端口
href  反正的url, == toString()
pathname 返回url中的路径地址
port 端口
protocol 协议
search 请求参数 "?xxxxx"

+查询字符串参数

function getQueryArgs() {
	var search = location.search;
	var len = search.length;
	var qs = ( len > 0 ? search.substring(1): "");
	var args = {};
	var items = qs.length? qs.split('&'):[];
	var item = null, name=null, value=null;
	
	for(var i=0;i < items.length; i++) {
		item = items[i].split('=');
		name = decodeURIComponent(item[0]);
		value = decodeURIComponent(item[1]);
		
		if( name.length ) {
			args[name] = value;
		}
	}
	
	return args;
}

属性比较多,不一一列举. 各浏览器的支持表现有所不同

appName, appVersion,onLine
Chrome中插件检测
function hasPlugin(name) {
	name = name.toLowerCase();
	for( var i=0; i< navigator.plugins.length; i++) {
		if( navigator.plugins[i].name.toLowerCase().indexOf(name) > -1 ) {
			return true;
		}
	}
}

screen

后续补充

history

history.go(); 1 -1 2 "url"

history.back();

history.forward();

history.length==0 第一个页面

原文地址:https://www.cnblogs.com/pengsn/p/12692990.html