<body>
<input type="button" onClick="newWin()" value="点击我,打开新窗口!">
<script>
function newWin(){
window.open('http://www.baidu.com', '_blank', 'width=,height=,top=,left=');
}
</script>
</body>
<script>
window.open();
window.open('http://baidu.com');
</script>
<body>
<input type="button" value="获得焦点" onclick="openWin()">
<script>
//确保新的窗口获得焦点:
function openWin(){
var oGet=window.open('', '', 'width=,height=');
oGet.document.write('<p>我是新打开的窗口</p>');
oGet.focus();
}
</script>
<input type="button" value="失去焦点" onclick="newWin()">
<script>
//确保新的窗口没有获得焦点:
function newWin(){
var lose=window.open('', '', 'width=,height=');
lose.document.write('<p>我是新打开的窗口</p>');
lose.blur();
}
</script>
</body>
<body>
<input type="button" value="打开" onclick="openWin()">
<script>
function openWin(){
var newWin=window.open('', 'newWindow', 'width=,height=');
newWin.document.write('<p>新窗口名称:'+ newWin.name + '</p>');
}
</script>
</body>
<body>
<input type="button" value="打开" onclick="openWin()">
<script>
function openWin(){
var newWin=window.open('', '', 'width=,height=');
newWin.document.write("<p>关闭我之后会向父窗口输入文本信息</p>");
newWin.focus();
newWin.opener.document.write('<p>我是父窗口,加载完成后,向我输出内容会覆盖我所有内容</p>');
}
</script>
</body>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-">
<title>JavaScript实例</title>
</head>
<body>
<br><br>
<h>用指定像素调整窗口大小:</h>
<input type="button" value="打开" onclick="openWin()"><br><br>
<input type="button" value="调整" onclick="byWin()">
<script>
var w;
function openWin(){
w=window.open('', '', 'width=,height=,top=');
w.focus();
}
function byWin(){
//如果不使用框架,可使用window代替top
w.top.resizeBy(,);
w.focus();
}
</script>
<h>将窗口的大小调整到指定的宽度和高度:</h>
<input type="button" value="打开" onclick="newWin()"><br><br>
<input type="button" value="调整" onclick="toWin()">
<script>
var w;
function newWin(){
w=window.open('', '', 'width=,height=');
w.focus();
}
function toWin(){
w.resizeTo(,);
w.focus();
}
</script>
<h>相对于当前位置移动新窗口:</h>
<input type="button" value="打开" onclick="oWin()"><br><br>
<input type="button" value="多移动几下" onclick="moveWin()">
<script>
var w;
function oWin(){
w=window.open('', '', 'width=,height=');
}
function moveWin(){
w.moveBy(,);
w.focus();
}
</script>
<h>移动新窗口到指定位置:</h>
<input type="button" value="打开" onclick="nWin()"><br><br>
<input type="button" value="移动" onclick="moveToWin()">
<script>
var w;
function nWin(){
w=window.open('', '', 'width=,height=');
}
function moveToWin(){
w.moveTo(,);
w.focus();
}
</script>
<h>由指定的像素数滚动内容:</h>
<input type="button" style="position:fixed;top:;" onclick="scrollWin()" value="由指定的像素数滚动内容">
<script>
function scrollWin(){
window.scrollBy(,);
}
</script>
<h>滚动到指定内容处:</h>
<input type="button" onclick="scrollWindow()" value="滚动到指定内容处">
<script>
function scrollWindow(){
window.scrollTo(,);
}
</script>
<br><br><br><br><br><br>
</body>
</html>
<body>
<input type="button" value="打印当前页面" onclick="printpage()">
<script>
function printpage(){
window.print();
}
</script>
</body>
//点击按钮关闭当前窗口 <input type="button" value="关闭窗口" onclick="window.close()">
//先用open打开保存的文档,然后再点击关闭窗口按钮,效果就达到了
<input type="button" value="打开窗口" onclick="window.open('close.html');">
<a href="javascript:window.opener=null;window.open('', '_self');window.close();">关闭</a>
<body>
<input type="button" value="打开" onclick="openWin()">
<input type="button" value="关闭" onclick="closeWin()">
<script>
function openWin(){
newWin=window.open('http://www.baidu.com', '', 'width=,height=,top=');
}
function closeWin(){
newWin.close();
}
</script>
</body>
<body>
<input type="button" value="打开'" onclick="openWin()">
<input type="button" value="关闭" onclick="closeWin()">
<input type="button" value="是否关闭" onclick="checkWin()">
<p id="p"></p>
<script>
var newWin;
function openWin(){
newWin=window.open('', '', 'width=,height=,top=');
}
function closeWin(){
if(newWin){
newWin.close();
}
}
var oP=document.getElementById('p');
function checkWin(){
if(!newWin){
oP.innerHTML='新窗口还没被打开!';
}
else{
if(newWin.closed){
oP.innerHTML='新窗口已关闭!';
}
else{
oP.innerHTML='新窗口未关闭!';
}
}
}
</script>
</body>
<body>
<div id="div"></div>
<script>
txt = '<p>Browser CodeName(浏览器代码名称): ' + navigator.appCodeName + '</p>';
txt+= '<p>Browser Name(浏览器名称): ' + navigator.appName + '</p>';
txt+= '<p>Browser Version(浏览器版本): ' + navigator.appVersion + '</p>';
txt+= '<p>Cookies Enabled(启用Cookies): ' + navigator.cookieEnabled + '</p>';
txt+= '<p>Platform(操作平台): ' + navigator.platform + '</p>';
txt+= '<p>User-agent header(由客户机发送服务器的 user-agent 头部信息): ' + navigator.userAgent + '</p>';
txt+= '<p>User-agent language(客户机代理语言): ' + navigator.systemLanguage + '</p>';
document.getElementById('div').innerHTML=txt;
</script>
</body>
<script> document.write(navigator.userAgent); </script>
<script>
document.write('操作平台:' + navigator.platform);
function userBrowser(){
var name = window.navigator.userAgent;
//IE浏览器
//判断IE和非IE可以使用ActiveXObject,只有IE支持该对象
//在IE中window.ActiveXObject返回一个对象,则判断为true
//其他浏览器都返回undefine,两个否返回false,进入或判断,也返回false
if(!!window.ActiveXObject || 'ActiveXObject' in window){
return 'IE浏览器';
}
//FF浏览器
else if(name.indexOf('Firefox') > -){
return 'Firefox浏览器';
}
//Chrome浏览器
else if(name.indexOf('Chrome') > -){
return 'Chrome浏览器';
}
//Opera浏览器
else if(name.indexOf('Opera') > -){
return 'Opera浏览器';
}
//Safari浏览器
else if(name.indexOf('Safari') > -){
return 'Safari浏览器';
}
else{
return 'unknow';
}
}
alert('浏览器类型为:' + userBrowser());
</script>
<script> //当前页面URL。若中间出现乱码百分号是中文转码后的显示。 document.write(window.location); </script> <input type="button" value="点击查看" onclick="window.location='http://www.baidu.com','_blank'"> </body>
<input type="button" value="点击加载" onclick="newDoc()">
<script>
function newDoc(){
window.location.assign('http://www.baidu.com')
}
</script>
<input type="button" value="点击载入" onclick="reloadPage()">
<script>
function reloadPage(){
location.reload()
}
</script>
<input type="button" value="点击替换" onclick="replaceDoc()">
<script>
function replaceDoc(){
window.location.replace('http://www.baidu.com')
}
</script>
<script>
document.write( '屏幕宽度:' + screen.width + 'px' );
document.write('<br>');
document.write( '屏幕高度:' + screen.height + 'px' );
</script>
<script>
document.write('可用宽度:' + screen.availWidth +'px');
document.write('<br>');
document.write('可用高度:' + screen.availHeight +'px');
</script>
var w = document.documentElement.clientWidth || document.body.clientWidth;
var h = document.documentElement.clientHeight || document.body.clientHeight;
<script>
//对于IE+、Chrome、Firefox、Opera 以及 Safari:
document.write('可视宽为:'+window.innerWidth + '<br>');
document.write('可视高为:'+window.innerHeight + '<br>'+ '<br>');
document.write('可视宽为:'+document.documentElement.clientWidth + '<br>');
document.write('可视高为:'+document.documentElement.clientHeight + '<br>'+ '<br>');
//注意该方法返回的数值与其他不同
document.write('可视宽为:'+document.body.clientWidth + '<br>');
document.write('可视高为:'+document.body.clientHeight + '<br>'+ '<br>');
var w= document.documentElement.clientWidth || document.body.clientWidth;
var h= document.documentElement.clientHeight || document.body.clientHeight;
document.write('可视宽为:'+ w +'<br>'+ '可视高为:' +h);
</script>
var w =document.documentElement.scrollWidth || document.body.scrollWidth; var h =document.documentElement.scrollHeight || document.body.scrollHeight;
<script>
//兼容性写法
var w =document.documentElement.scrollWidth || document.body.scrollWidth;
var h=document.documentElement.scrollHeight || document.body.scrollHeight;
document.write('网页内容宽为:'+ w +'<br>'+ '网页内容高为:' +h);
</script>
<script>
//兼容性写法
var w = document.documentElement.offsetWidth || document.body.offsetWidth;
var h = document.documentElement.offsetHeight || document.body.offsetHeight;
document.write('网页内容宽为:'+ w +'<br>'+ '网页内容高为:' +h);
</script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-">
<title>JavaScript实例</title>
<script>
//几款浏览器每次滚动,距离顶部的距离都不一样:
//在Chrome为:-----。都是整数递进。
//而在FF下则为:----。每次递进。
//而在IE下则为:----。每次递进则为。
window.onload=function (){
document.onclick=function (){
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;
alert(scrollTop);
};
};
</script>
</head>
<body style="height:px">
</body>
</html>
<script> var oD=new Date(); //从当天起天也就是周后是几号 oD.setDate(oD.getDate()+); //设置过期时间周。可在查看cookie中看到user的过期时间为周后 document.cookie='user=小白;expires='+oD; //浏览器关闭删除本条cookie。pass的过期时间为在会话结束时。 document.cookie='pass='; //读取cookie alert(document.cookie); </script>
<script> var oD=new Date(); oD.setDate(oD.getDate()+); document.cookie='user=小白;expires='+oD; document.cookie='pass='; //可在查看cookie中看到user和pass的内容都被新的cookie替换了 document.cookie='user=小明;expires='+oD; document.cookie='pass='; //读取cookie alert(document.cookie); </script>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-">
<title>Cookie封装函数</title>
</head>
<body>
<script>
//设置cookie
//参数:cookie的名字,参数:cookie的值,参数:cookie过期时间
function setCookie(name, value, iDay){
var oDate=new Date();
oDate.setDate(oDate.getDate()+iDay);
document.cookie=name+'='+value+'; expires='+oDate;
}
//userName一年后过期,passWord两周后过期。
setCookie('userName', '小白', );
setCookie('passWord', '', );
//获取cookie
//参数为cookie的名称
function getCookie(name){
//用字符串将cookie分割,注意要用:默认的cookie样式,分号加空格。
var arr=document.cookie.split('; ');
for(var i=;i<arr.length;i++){
//默认字符串显示为:a=; b=; c=
//所以用等号再做一次分隔
var result=arr[i].split('=');
//result的第一位存名称
//如果第一位等于name,就说明找到想要的了,就返回第二位的值。
if(result[]==name){
//result的第二位存值
return result[];
}
}
//如果没有cookie就返回一个空字符串。比如有些用户是第一次进入网站,就没有产生cookie。
return '';
}
//获取cookie中passWord的值
alert(getCookie('passWord'));
//参数为删除哪条cookie
function removeCookie(name){
//参数:cookie的值,表示随便一个。参数:昨天过期,立马删除。
setCookie(name, , -);
}
//将cookie中userName和passWord删除。
//在点击查看页面信息,之前保存的cookie就不存在了。
removeCookie('userName');
removeCookie('passWord');
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-">
<title>记住上一次的用户名</title>
<script>
function setCookie(name, value, iDay){
var oDate=new Date();
oDate.setDate(oDate.getDate()+iDay);
document.cookie=name+'='+value+'; expires='+oDate;
}
function getCookie(name){
var arr=document.cookie.split('; ');
for(var i=;i<arr.length;i++){
var result=arr[i].split('=');
if(result[]==name){
return result[];
}
}
return '';
}
function removeCookie(name){
setCookie(name, , -);
}
window.onload=function (){
var oForm=document.getElementById('form');
var oUser=document.getElementsByName('user')[];
//在点击提交按钮时发生的事件
oForm.onsubmit=function (){
//创建一个cookie,值为用户名输入的值,天后过期
setCookie('user', oUser.value, );
};
//用户名的值为获取cookie中的user
oUser.value=getCookie('user');
};
</script>
</head>
<body>
//index.html为本文档文件名
<form id="form" action="index.html">
用户名:<input type="text" name="user"><br>
密 码:<input type="password" name="pass"><br>
<input type="submit" name="" value="登录">
</form>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有