php课程---Windows.open()方法参数详解
1, 最基本的弹出窗口代码
window.open('page.html');
2, 经过设置后的弹出窗口
window.open('page.html', 'newwindow', 'height=100, width=400, top=0,
left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,
location=no, status=no') //该句写成一行代码
参数解释:
window.open 弹出新窗口的命令;
'page.html' 弹出窗口的文件名;
'newwindow' 弹出窗口的名字(不是文件名),非必须,可用空''代替;
height=100 窗口高度;
width=400 窗口宽度;
top=0 窗口距离屏幕上方的象素值;
left=0 窗口距离屏幕左侧的象素值;
toolbar=no 是否显示工具栏,yes为显示;
menubar,scrollbars 表示菜单栏和滚动栏。
resizable=no 是否允许改变窗口大小,yes为允许;
location=no 是否显示地址栏,yes为允许;
status=no 是否显示状态栏内的信息(通常是文件已经打开),yes为允许;
3, 用函数控制弹出窗口
下面是一段完整的代码
<html>
<head>
<script LANGUAGE="JavaScript">
<!--
function openwin() {
window.open ("page.html", "newwindow", "height=100, width=400, toolbar
=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no")
//写成一行
}
//-->
</script>
</head>
<body onload="openwin()">
任意的页面内容...
</body>
</html>
解释:这里定义了一个函数openwin(), 函数内容就是打开一个窗口。在调用它之前没有任何用途。怎么调用呢?
方法一:<body onload="openwin()"> 浏览器读页面时弹出窗口;
方法二:<body onunload="openwin()"> 浏览器离开页面时弹出窗口;
方法三:用一个连接调用:
<a href="#" onclick="openwin()"> 打开一个窗口</a>
注意:使用的"#"是虚连接。
方法四:用一个按扭调用:
<input type="button" onclick="openwin()" value="打开窗口" />
4, 弹出两个窗口
对代码稍微改动如下:
<script LANGUAGE="JavaScript">
<!--
function openwin() {
window.open ("page.html", "newwindow", "height=100, width=100, top=0,
left=0,toolbar=no, menubar=no, scrollbars=no, resizable=no, location=n
o, status=no")//写成一行
window.open ("page2.html", "newwindow2",
"height=100, width=100, top=100, left=100,toolbar=no, menubar=no,
scrollbars=no, resizable=no, loca tion=no, status=no")//写成一行
}
//-->
</script>
为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可。最后用上面的说过的四种方法调用即可。
注意:2个窗口的name(newwindow与 newwindow2)不要相同,或者干脆全部为空。
5, 主窗口打开文件1.htm,同时弹出小窗口page.html
如下代码加入主窗口<head>区:
function openwin()
{
window.open("page.html","","width=200,height=200")
}
加入body区:
<a href="1.htm" onclick="openwin()">open</a>即可。
6, 弹出的窗口之定时关闭控制
将一小段代码加入弹出的页面(注意是加入page.html的HTML中,可不是主页面中,否则......),让它在10秒后自动关闭是不是更酷了?
function closeit()
{
setTimeout("selft.close()", 10000) //毫秒
}
然后,在body 中添加:<body onload="closeit()">即可。
7, 在弹出窗口中加上一个关闭按扭
<input type="button" value="关闭" onclick="window.close()">
8, 内包含的弹出窗口---一个页面两个窗口
上面的例子都包含两个窗口,一个是主窗口,另一个是弹出的小窗口。通过下面的例子,你可以在一个页面内完成上面的效果。
<html>
<head>
<SCRIPT LANGUAGE="JavaScript">
function openwin()
{
OpenWindow=window.open("", "newwin", "height=250, width=250,toolbar=no ,scrollbars="+scroll+",menubar=no");
//写成一行
OpenWindow.document.write("<TITLE>例子</TITLE>")
OpenWindow.document.write("<BODY BGCOLOR=#ffffff>")
OpenWindow.document.write("<h1>Hello!</h1>")
OpenWindow.document.write("New window opened!")
OpenWindow.document.write("</BODY>")
OpenWindow.document.write("</HTML>")
OpenWindow.document.close()
}
</SCRIPT>
</head>
<body>
<a href="#" onclick="openwin()">打开一个窗口</a>
<input type="button" onclick="openwin()" value="打开窗口">
</body>
</html>
OpenWindow.document.write()里面的代码不就是标准的HTML吗?只要按照 格式写更多的行即可。千万注意多一个标签或少一个标签就会出现错误。记得用 OpenWindow.document.close()结束啊。
9, 终极应用---弹出的窗口这Cookie控制
回想一下,上面的弹出窗口虽然酷,但是有一点小毛病,比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?
有解决的办法吗?我们使用cookie来控制即可。
首先,将如下代码加入主页面的Html的head区:
function openwin(){
window.open("page.html","","width=200,height=200")
}
function get_cookie(Name)
{
var search=Name+"=";
var returnvalue="";
if(document.cookie.length>0){
if (offset != -1) {
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1)
end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end));
}
}
return returnvalue;
}
function ladpopup()
{
if(get_cookie('popped=yes'))
{
openwin()
document.cookie="popped=yes";
}
}
最后,用<body onload="loadpopup()">
php课程---Windows.open()方法参数详解的更多相关文章
- Window.open()方法参数详解
Window.open()方法参数详解 1, 最基本的弹出窗口代码 window.open('page.html'); 2, 经过设置后的弹出窗口 window.open('page.html ...
- ajax方法参数详解与$.each()和jquery里面each方法的区别
JQuery中$.ajax()方法参数详解 url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为g ...
- intent.putExtra()方法参数详解
[开篇骂几句:fuck]1.扯淡intent.putExtra()怎么使用?2.胡说intent.putExtra(); [扯淡:其实你在问它怎么用的时候,你要明白,你知道不知道这是个什么东东,有必要 ...
- JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- JQuery中$.ajax()方法参数详解 及 async属性说明
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- JQuery中$.ajax()方法参数详解(转载)
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- $.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- 转:JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
- (转)JQuery中$.ajax()方法参数详解
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如put和 ...
随机推荐
- SpringRMI解析2-RmiServiceExporter逻辑脉络
配置文件是Spring的核心,在配置文件中我们可以看到,定义了两个bean,其中一个是对接口实现类的发布,而另一个则是对RMI服务的发布,使用org.springframework.remoting. ...
- 《DSP using MATLAB》示例Example5.3
- IconFont和FontAwesome的区别?
一.[Iconfont] Iconfont支持所有低版本浏览器: Iconfont的图标库更大: Iconfont可以用自己上传的svg,但是要花费大量时间和耐心去设计AI图标: Iconfont的使 ...
- 02 CSS/javaScript
CSS(Cascading Style Sheets)是层叠样式表用来设置网页的显示效果.可以解决html代码对样式定义的重复,提高了后期样式代码的可维护性,并增强了网页的显示效果功能.简单一句话:C ...
- Codeforces Round #347 (Div. 2)
unrating的一场CF A - Complicated GCD #include <bits/stdc++.h> const int N = 1e5 + 5; char a[105], ...
- Hash(LCP) || 后缀数组 LA 4513 Stammering Aliens
题目传送门 题意:训练指南P225 分析:二分寻找长度,用hash值来比较长度为L的字串是否相等. #include <bits/stdc++.h> using namespace std ...
- underscore.js依赖库函数分析二(查找)
查找: 在underscore.js封装了对dom查找的操作,find()和filter()函数,find()函数的查找操作是返回首个与条件相符的元素值,filter()函数是找到与条件相符的所有元素 ...
- Codeforces Round #366 Div.2[11110]
这次出的题貌似有点难啊,Div.1的Standing是这样的,可以看到这位全站排名前10的W4大神也只过了AB两道题. A:http://codeforces.com/contest/705/prob ...
- Unity 状态转化机器
using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /** 有限状 ...
- POJ 2955 Brackets(区间DP)
题目链接 #include <iostream> #include <cstdio> #include <cstring> #include <vector& ...