14-29.htm

来自「JavaScript学习的网页教程。内容简单易懂」· HTM 代码 · 共 38 行

HTM
38
字号
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=gb2312">
<TITLE>window对象的focus()和blur()方法示例</TITLE>
<SCRIPT LANGUAGE="JavaScript">
var newWindow = null                     // declare global variable name,null相当于false
function makeNewWindow() {
	if (!newWindow||newWindow.closed) {	 // check if window already exists   
		newWindow = window.open("","","width=350,height=150")     
		// store new window object in global variable
		// assemble content for new window
		var newContent = "<HTML><TITLE>新打开的子窗口</TITLE></HEAD>" 
		newContent += "<BODY bgColor='yellow'><H2>这是一个背景色为yellow的由主窗口打开的子窗口</H2>"
		newContent += "<FORM><INPUT TYPE='button' VALUE='将主窗口放到前台' onClick='self.opener.focus()'>"
		//self.opener用来指定主(父)窗口		
		newContent += "<INPUT TYPE='button' VALUE='将本窗口放到后台' onClick='self.blur()'>"
		newContent += "</FORM></BODY></HTML>"
		
		newWindow.document.write(newContent)  // write HTML to new window document
	} else {	
	newWindow.focus()                         // window already exists, so bring it forward
	}
}
</SCRIPT>
</HEAD>
<BODY>
<H2>
<FONT face="华文彩云">本窗口是主窗口</FONT>
</H2>
<br>
<FONT size="4">单击下面的按钮将打开一个子窗口:</FONT>
<FORM>
<br>
<INPUT TYPE="button" NAME="newOne" VALUE="打开一个新的子窗口" onClick="makeNewWindow()">
</FORM>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?