注意: 拷贝代码后需要 查找 "/ ", 并替换为 "/". (不加引号) 原因: CSDN 的编码器在行末自动添加空格符" ", 而这段代码正好使用 js 的 / 在行末作为行链接, 因此行末就是空格, 而不是 /, 需要手动转正.
-
Javascript: 弹出窗口一例 By shawl.qiu
说明:
Js 弹出窗口其实很简单, 不过本例可能有点复杂哦 ^^
加一个焦点, 加一个清空内容, 加一个事件响应, 加一个居中显示.
shawl.qiu
2006-10-24
http://blog.csdn.net/btbtd
内容:
- linenum
- <script type="text/javascript">
- //<![CDATA[
- function fPopupWin(){
- var w=h=500;
- x=(screen.width-w)/2;
- y=(screen.height-h)/2;
- var n=open('','newWin','width='+w+',height='+h+',left='+x+',right='+x+',top='+y+',bottom='+y)
- n.document.write('/
- <script>/
- document.write("temp"); /* 临时内容, 去掉出错 */ /
- document.body.innerHTML=""; /* 清空页面内容 */ /
- document.οnclick=function(){ close();} /* 单击关闭窗口 */ /
- <//script>');
- n.document.write('<h2>pop up window</h2> <!--写入显示内容--> /
- <script>/
- document.write(("<p>popup name: ").bold()+name.fontcolor("red")+"</p>");/
- <//script>');
- n.focus(); // 焦点移到弹出窗口
- } // shawl.qiu script
- //]]>
- </script>
- <a href="#" οnclick="fPopupWin()">pop up window</a>