求window.open的全部参数

pennyxu 2002-08-14 12:41:10
求window.open的全部参数
...全文
45 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
pennyxu 2002-08-27
  • 打赏
  • 举报
回复
太感谢了,结贴给分
flylyke 2002-08-14
  • 打赏
  • 举报
回复
oNewDoc = document.open(sUrl [, sName] [, sFeatures] [, bReplace])
happyboy0123 2002-08-14
  • 打赏
  • 举报
回复
只有一个角的同志们,多问点这种方式的问题,让我们更多地进步吧!
95306 2002-08-14
  • 打赏
  • 举报
回复
【1、最基本的弹出窗口代码】
其实代码非常简单:
<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html')
-->
</SCRIPT>
因为着是一段javascripts代码,所以它们应该放在<SCRIPT LANGUAGE="javascr

ipt">标签和</script>之间。<!-- 和 -->是对一些版本低的浏览器起作用,在这

些老浏览器中不会将标签中的代码作为文本显示出来。要养成这个好习惯啊。
window.open ('page.html') 用于控制弹出新的窗口page.html,如果page.html

不与主窗口在同一路径下,前面应写明路径,绝对路径(http://)和相对路径(..

/)均可。
用单引号和双引号都可以,只是不要混用。
这一段代码可以加入HTML的任意位置,<head>和</head>之间可以,<body>间</b

ody>也可以,越前越早执行,尤其是页面代码长,又想使页面早点弹出就尽量往

前放。

【2、经过设置后的弹出窗口】
下面再说一说弹出窗口的设置。只要再往上面的代码中加一点东西就可以了。

我们来定制这个弹出的窗口的外观,尺寸大小,弹出的位置以适应该页面的具体

情况。

<SCRIPT LANGUAGE="javascript">
<!--
window.open ('page.html', 'newwindow', 'height=100, width=400, top=0,

left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no,location=n

o, status=no')
//写成一行
-->
</SCRIPT>

参数解释:
<SCRIPT LANGUAGE="javascript"> js脚本开始;
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为允许;


</SCRIPT> js脚本结束

【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、同时弹出2个窗口】
对源代码稍微改动一下:
<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=1

00, left=100,toolbar=no, menubar=no, scrollbars=no, resizable=no, loca

tion=no, status=no")
//写成一行
}
//-->
</script>
为避免弹出的2个窗口覆盖,用top和left控制一下弹出的位置不要相互覆盖即可

。最后用上面说过的四种方法调用即可。
注意:2个窗口的name(newwindows和newwindow2)不要相同,或者干脆全部为空。

OK?

【5、主窗口打开文件1.htm,同时弹出小窗口page.html】

如下代码加入主窗口<head>区:

<script language="javascript">
<!--
function openwin() {
window.open("page.html","","width=200,height=200")
}
//-->
</script>
加入<body>区:
<a href="1.htm" onclick="openwin()">open</a>即可。

【6、弹出的窗口之定时关闭控制】

下面我们再对弹出的窗口进行一些控制,效果就更好了。如果我们再将一小段

代码加入弹出的页面(注意是加入到page.html的HTML中,可不是主页面中,否则

...),让它10秒后自动关闭是不是更酷了?
首先,将如下代码加入page.html文件的<head>区:
<script language="JavaScript">

function closeit() {

setTimeout("self.close()",10000) //毫秒

}

</script>
然后,再用<body onload="closeit()"> 这一句话代替page.html中原有的<BO

DY>这一句就可以了。(这一句话千万不要忘记写啊!这一句的作用是调用关闭窗

口的代码,10秒钟后就自行关闭该窗口。)

【7、在弹出窗口中加上一个关闭按钮】
<FORM>
<INPUT TYPE='BUTTON' VALUE='关闭' onClick='window.close()'>
</FORM>
呵呵,现在更加完美了!

【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控制】

回想一下,上面的弹出窗口虽然酷,但是有一点小毛病(沉浸在喜悦之中,一定

没有发现吧?)比如你将上面的脚本放在一个需要频繁经过的页面里(例如首页),

那么每次刷新这个页面,窗口都会弹出一次,是不是非常烦人?:-(
有解决的办法吗?Yes! ;-) Follow me.
我们使用cookie来控制一下就可以了。
首先,将如下代码加入主页面HTML的<HEAD>区:

<script>
function openwin(){
window.open("page.html","","width=200,height=200")
}
function get_cookie(Name) {
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
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 loadpopup(){
if (get_cookie('popped')==''){
openwin()
document.cookie="popped=yes"
}
}

</script>

然后,用<body onload="loadpopup()">(注意不是openwin而是loadpop啊!)

替换主页面中原有的<BODY>这一句即可。你可以试着刷新一下这个页面或重新进

入该页面,窗口再也不会弹出了。真正的Pop-Only-Once!
willway 2002-08-14
  • 打赏
  • 举报
回复
长见识了,ありがとう ございます
alalya 2002-08-14
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/methods/open_0.asp
meizz 2002-08-14
  • 打赏
  • 举报
回复
indow.open的例子和使用方法以及参数说明:

<SCRIPT>
<!--
window.open ('http://www.csdn.net/','newwindow','height=100,width=400,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')
//写成一行
-->
</SCRIPT>

window.open()详细使用方法:

支持环境 JavaScript1.0+/JScript1.0+/Nav2+/IE3+/Opera3+

语法 window.open(pageURL,name,parameters)

pageURL 子窗口路径
name 子窗口句柄
parameters 窗口参数(各参数用逗号分隔)

参数 | 取值范围 | 说明
| |
alwaysLowered | yes/no | 指定窗口隐藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上
depended | yes/no | 是否和父窗口同时关闭
directories | yes/no | Nav2和3的目录栏是否可见
height | pixel value | 窗口高度
hotkeys | yes/no | 在没菜单栏的窗口中设安全退出热键
innerHeight | pixel value | 窗口中文档的像素高度
innerWidth | pixel value | 窗口中文档的像素宽度
location | yes/no | 位置栏是否可见
menubar | yes/no | 菜单栏是否可见
outerHeight | pixel value | 设定窗口(包括装饰边框)的像素高度
outerWidth | pixel value | 设定窗口(包括装饰边框)的像素宽度
resizable | yes/no | 窗口大小是否可调整
screenX | pixel value | 窗口距屏幕左边界的像素长度
screenY | pixel value | 窗口距屏幕上边界的像素长度
scrollbars | yes/no | 窗口是否可有滚动栏
titlebar | yes/no | 窗口题目栏是否可见
toolbar | yes/no | 窗口工具栏是否可见
Width | pixel value | 窗口的像素宽度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上
boy_digger 2002-08-14
  • 打赏
  • 举报
回复
为什么不到msdn上去看一下呢!

superszhu 2002-08-14
  • 打赏
  • 举报
回复
过来蹭点分:

Syntax

oNewWindow=window.open([sURL] [, sName] [, sFeatures] [, bReplace])

Parameters

sURL Optional. String that specifies the URL of the document to display. If no URL is specified, a new window with about:blank is displayed.
sName Optional. String that specifies the name of the window. This name is used as the value for the TARGET attribute on a FORM or an A element.
In Internet Explorer 5 and later, specifying the value _search opens sURL in the browser's search pane.

sFeatures Optional. String that specifies the window ornaments to display. The following features are supported: channelmode = { yes | no | 1 | 0 } Specifies whether to display the window in theater mode and show the channel band. The default is no.
directories = { yes | no | 1 | 0 } Specifies whether to add directory buttons. The default is yes.
fullscreen = { yes | no | 1 | 0 } Specifies whether to display the browser in a full-screen or normal window. The default is no, which displays the browser in a normal window.
Use full-screen mode carefully. Because this mode hides the browser's title bar and menus, you should always provide a button or other visual clue to help the user close the window. ALT+F4 also closes the new window.

height = number Specifies the height of the window, in pixels. The minimum value is 100.
left = number Specifies the left position, in pixels. This value is relative to the upper-left corner of the screen.
location = { yes | no | 1 | 0 } Specifies whether to display the input field for entering URLs directly into the browser. The default is yes.
menubar = { yes | no | 1 | 0 } Specifies whether to display the menu bar. The default is yes.
resizable = { yes | no | 1 | 0 } Specifies whether to display resize handles at the corners of the window. The default is yes.
scrollbars = { yes | no | 1 | 0 } Specifies whether to display horizontal and vertical scroll bars. The default is yes.
status = { yes | no | 1 | 0 } Specifies whether to add a status bar at the bottom of the window. The default is yes.
titlebar = { yes | no | 1 | 0 } Specifies whether to display a title bar for the window. This parameter is ignored unless the caller is an html application or a trusted dialog box. The default is yes.
toolbar = { yes | no | 1 | 0 } Specifies whether to display the browser toolbar, making buttons such as Back, Forward, and Stop available. The default is yes.
top = number Specifies the top position, in pixels. This value is relative to the upper-left corner of the screen.
width = number Sets the width of the window, in pixels. The minimum value is 100.

bReplace Optional. Boolean that specifies whether the URL that is loaded into the new page should create a new entry in the window's browsing history or replace the current entry in the browsing history. If set to true, no new history entry is created.

Return Value

Returns a reference to the new window object. Use this reference to script properties and methods on the new window.

Remarks

By default, the open method creates a window that has a default width and height and the standard menu, toolbar, and other features of Microsoft® Internet Explorer. You can alter this set of features by using the sFeatures parameter. This parameter is a string consisting of one or more feature settings. When one feature is specified, any additional features that are not specified are disabled. If no features are specified, the window features maintain their default values. In addition to enabling a feature with the specified possible value, simply listing the feature name also enables that feature for the new window.

Internet Explorer 5 allows further control over windows through the implementation of title in the sFeatures parameter of the open method. Turn off the title bar by opening the window from a trusted application, such as Microsoft® Visual Basic® or an HTML Application (HTA). These applications are considered trusted, because each uses Internet Explorer interfaces instead of the browser.

孟子E章 2002-08-14
  • 打赏
  • 举报
回复
open Method


Opens a new window and loads the document specified by a given URL.

Syntax

oNewWindow = window.open( [sURL] [, sName] [, sFeatures] [, bReplace])
Parameters

sURL
可选. String that specifies the URL of the document to display. If no URL is specified, a new window with about:blank is displayed.

sName
可选. String that specifies the name of the window. This name is used as the value for the TARGET attribute on a form or an a element._blank The url is loaded into a new, unnamed window.

_parent
The sURL is loaded into the current frame's parent. If the frame has no parent, this value acts as the value _self.

_search
Available in Microsoft? Internet Explorer 5 and later. The sURL is opened in the browser's search pane.

_self T
he current document is replaced with the specified sURL

_top
sURL replaces any framesets that may be loaded. If there are no framesets defined, this value acts as the value _self.

sFeatures
可选. This String parameter is a list of items separated by commas. Each item consists of an option and a value, separated by an equals sign (for example, "fullscreen=yes, toolbar=yes"). The following features are supported.channelmode = { yes | no | 1 | 0 } Specifies whether to display the window in theater mode and show the channel band. The default is no.
directories = { yes | no | 1 | 0 } Specifies whether to add directory buttons. The default is yes.
fullscreen = { yes | no | 1 | 0 } Specifies whether to display the browser in full-screen mode. The default is no. Use full-screen mode carefully. Because this mode hides the browser's title bar and menus, you should always provide a button or other visual clue to help the user close the window. ALT+F4 closes the new window.
height = number Specifies the height of the window, in pixels. The minimum value is 100.
left = number Specifies the left position, in pixels. This value is relative to the upper-left corner of the screen.
location = { yes | no | 1 | 0 } Specifies whether to display the input field for entering URLs directly into the browser. The default is yes.
menubar = { yes | no | 1 | 0 } Specifies whether to display the menu bar. The default is yes.
resizable = { yes | no | 1 | 0 } Specifies whether to display resize handles at the corners of the window. The default is yes.
scrollbars = { yes | no | 1 | 0 } Specifies whether to display horizontal and vertical scroll bars. The default is yes.
status = { yes | no | 1 | 0 } Specifies whether to add a status bar at the bottom of the window. The default is yes.
titlebar = { yes | no | 1 | 0 } Specifies whether to display a title bar for the window. This parameter is ignored unless the calling application is an HTML Application or a trusted dialog box. The default is yes.
toolbar = { yes | no | 1 | 0 } Specifies whether to display the browser toolbar, making buttons such as Back, Forward, and Stop available. The default is yes.
top = number Specifies the top position, in pixels. This value is relative to the upper-left corner of the screen.
width = number Sets the width of the window, in pixels. The minimum value is 100.

bReplace 可选. When the sURL is loaded into the same window, this Boolean parameter specifies whether the sURL creates a new entry or replaces the current entry in the window's history list. true sURL replaces the current document in the history list
false sURL creates a new entry in the history list.

通过页面性能测试概念+页面加载过程+页面性能指标+页面性能测试工具的学习,可以学到如下内容:①WEB网站页面性能的指标(白屏时间、首屏加载完成时间、FP、FCP、DCL、CLS、FPS等);②WEB网站页面性能测试策略;③WEB网站页面加载过程(前端基础语言:HTML+CSS+JavaScript,DOM、CSSOM、渲染树、布局、绘制);④WEB网站页面性能测试工具的实际操作和功能介绍(开发者工具:控制台、网络、性能、Lighthouse、FPS渲染统计等);⑤WEB网站页面性能测试报告编写。⑥WEB网站页面性能测试步骤和实际操作。课程内容:第一章:课程简介1、课程介绍2、课程大纲第二章:页面性能测试1、页面性能测试概念2、页面性能测试专业术语3、页面性能测试策略第三章:页面加载过程1、HTML概念,HTML5实例,HTML5文档2、CSS概念,CSS实例,CSS文档3、JavaScript概念,JavaScript脚本实例和作用4、DOM和CSSOM理解5、HTML5渲染引擎理解6、HTML5页面内容渲染的过程,HTML渲染树第四章:页面性能测试工具1、页面性能测试具体工具2、Chrome开发者工具介绍第五章:页面性能测试工具-控制台:window.performance1、控制台:window.performance介绍2、window.performance.timing执行结果加载字段理解3、window.performance.timing执行结果属性对应页面阶段理解4、window.performance页面性能参数计算5、window.performance页面性能关键指标计算第六章:页面性能测试工具-网络面板1、Chrome-开发者工具-网络面板介绍2、Chrome-开发者工具-网络-瀑布流指标第七章:页面性能测试工具-性能面板1、Chrome-开发者工具-性能面板-使用方法2、Chrome-开发者工具-性能面板介绍3、Chrome-开发者工具-性能面板-控制按钮区域4、Chrome-开发者工具-性能面板-Overview区域5、Chrome-开发者工具-性能面板-火焰图区域6、Chrome-开发者工具-性能面板-内存图区域7、Chrome-开发者工具-性能面板-统计汇总区域8、Chrome-开发者工具-性能面板-统计汇总区域-摘要内容9、Chrome-开发者工具-性能面板-统计汇总区域-事件时长、调用、发生顺序第八章:页面性能测试工具-FPS监控1、Chrome-开发者工具-FPS监控-FPS介绍、FPS视觉效果、FPS查看方法第九章:页面性能测试-Lighthouse面板1、Chrome-开发者工具-Lighthouse介绍、操作方法、运行的生命周期2、Chrome-开发者工具-Lighthouse报告指标分析3、Chrome-开发者工具-Lighthouse的报告优化建议第十章:页面性能测试工具-Performance insights面板1、Chrome-开发者工具-Performance insights操作方法2、Chrome-开发者工具-Performance insights分析报告第十一章:网速调研1、全国网速的调研和本机网速测试第十二章:页面性能测试总结1、页面性能测试指标采集方式2、页面性能测试报告3、页面性能测试-操作步骤​

87,922

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧