反饋已提交
網絡繁忙
Window 对象表示浏览器中打开的窗口。
如果文档包含框架(frame 或 iframe 标签),浏览器会为 HTML 文档创建一个 Window 对象,并为每个框架创建一个额外的 Window 对象。
Window对象表示一个浏览器窗口或一个框架。在客户端 JavaScript 中,Window 对象是全局对象,所有的表达式都在当前的环境中计算。
可以通过 Window 来引用 Window 对象,通常情况下可以直接使用 Winodw下的方法。如可以只写 document,而不必写 window.document。
同样,可以把当前窗口对象的方法当作函数来使用,如只写 alert(),而不必写 window.alert()。
显示一个对话框
显示一个确认框
通过点击按钮来打开一个窗口
打开一个新窗口,并控制其外观
显示提示框
close() 方法用于关闭浏览器窗口。方法 close() 将关闭有 window 指定的顶层浏览器窗口。某个窗口可以通过调用 self.close() 或只调用 close() 来关闭其自身。注:只有通过 JavaScript 代码打开的窗口才能够由 JavaScript 代码关闭。这阻止了恶意的脚本终止用户的浏览器。
显示带有一段消息和一个确认按钮的警告框。效果如下:
JS 脚本如下:
<script type="text/javascript">function display_alert() { alert("I am an alert box!!") }</script>
完整代码如下:
<html><head><script type="text/javascript">function display_alert() { alert("I am an alert box!!") }</script></head><body><input type="button" onclick="display_alert()"value="Display alert box" /></body></html>
confirm() 方法用于显示一个带有指定消息和 OK 及取消按钮的对话框。如果用户点击确定按钮,则 confirm() 返回 true。如果点击取消按钮,则 confirm() 返回 false。效果如下:注:在用户点击确定按钮或取消按钮把对话框关闭之前,它将阻止用户对浏览器的所有输入。在调用 confirm() 时,将暂停对 JavaScript 代码的执行,在用户作出响应之前,不会执行下一条语句。
<script type="text/javascript">function show_confirm(){var r=confirm("Press a button!");if (r==true) { alert("You pressed OK!"); }else { alert("You pressed Cancel!"); }}</script>
<html><head><script type="text/javascript">function show_confirm(){var r=confirm("Press a button!");if (r==true) { alert("You pressed OK!"); }else { alert("You pressed Cancel!"); }}</script></head><body><input type="button" onclick="show_confirm()" value="Show a confirm box" /></body></html>
prompt() 方法用于显示可提示用户进行输入的对话框。语法为
prompt(text,defaultText)
如果用户单击提示框的取消按钮,则返回 null。如果用户单击确认按钮,则返回输入字段当前显示的文本。效果如下:
注:在用户点击确定按钮或取消按钮把对话框关闭之前,它将阻止用户对浏览器的所有输入。在调用 prompt() 时,将暂停对 JavaScript 代码的执行,在用户作出响应之前,不会执行下一条语句
JS 代码如下:
<script type="text/javascript">function disp_prompt() { var name=prompt("请输入您的名字","FR") if (name!=null && name!="") { document.write("你好," + name + "!") } }</script>
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript"> function disp_prompt() { var name=prompt("请输入您的名字","FR") if (name!=null && name!="") { document.write("你好," + name + "!") } } </script> </head> <body> <input type="button" onclick="disp_prompt()" value="显示一个提示框" /> </body> </html>
打开一个新的浏览器窗口或查找一个已命名的窗口。使用语法:
window.open(URL,name,features,replace)
注:请不要混淆方法 window.open() 与方法 document.open(),这两者的功能完全不同。为了使您的代码清楚明白,请使用 window.open(),而不要使用 open()
比如:
window.open("https://help.finereport.com/");
用于打印当前窗口的内容。
调用 print() 方法所引发的行为就像用户单击浏览器的打印按钮。通常,这会产生一个对话框,让用户可以取消或定制打印请求。效果如下:
window.print()
文 檔回 饋
滑鼠選中內容,快速回饋問題
滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。
不再提示
10s後關閉