站长论坛

标题: JavaScript页面刷新与弹出窗口问题解决方法 [打印本页]

作者: ajax    时间: 2007-10-6 14:28
标题: JavaScript页面刷新与弹出窗口问题解决方法
1.无提示刷新网页

大家有没有发现,有些网页,刷新的时候,会弹出一个提示窗口,点“确定”才会刷新。

而有的页面不会提示,不弹出提示窗口,直接就刷新了.

如果页面没有form,则不会弹出提示窗口。如果页面有form表单,

a)< form method="post" ...> 会弹出提示窗口

b)< form method="get" ...> 不会弹出

2.javascript刷新页面的方法

window.location.reload();

使用window.open()弹出的弹出窗口,刷新父窗口

window.opener.location.reload()

使用window.showDialog弹出的模式窗口

window.dialogArguments.location.reload();

3.javascript弹出窗口代码

下面给两个弹出屏幕居中窗口的例子

window.open()方式
  1. function ShowDialog(url) {
  2.             var iWidth=300; //窗口宽度
  3.             var iHeight=200;//窗口高度
  4.             var iTop=(window.screen.height-iHeight)/2;
  5.             var iLeft=(window.screen.width-iWidth)/2;
  6.             window.open(
  7.             url,"Detail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,
  8.             Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft
  9.             );
  10.            }
  11. window.showModalDialog方式

  12. function ShowDialog(url) {
  13.             var iWidth=300; //窗口宽度
  14.             var iHeight=200;//窗口高度
  15.             var iTop=(window.screen.height-iHeight)/2;
  16.             var iLeft=(window.screen.width-iWidth)/2;
  17.             window.showModalDialog(
  18.             url,window,"dialogHeight: "+iHeight+"px;dialogWidth: "+iWidth+"px;
  19.             dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:no"
  20. );
  21.           }
复制代码
注意这里的第二个参数,window

4.模式窗口数据不刷新(缓存)问题

在jsp页面加入如下语句
  1. <%
  2.        response.setHeader("Pragma","No-Cache");
  3.        response.setHeader("Cache-Control","No-Cache");
  4.        response.setDateHeader("Expires", 0);
  5. %>
复制代码
5.模式窗口中,链接弹出新窗口问题

在< /head >和< body >间加入< base target="_self" >

6.无提示关闭页面的方法
  1. function CloseWin(){
  2.      var ua = navigator.userAgent; var ie = navigator.appName==
  3. "Microsoft Internet Explorer"?true:false;
  4.      if(ie){
  5. var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ")+5,
  6. ua.indexOf(";",ua.indexOf("MSIE "))));
  7.      if( IEversion< 5.5){
  8.      var str = '';
  9.      document.body.insertAdjacentHTML("beforeEnd", str);
  10.      document.all.noTipClose.Click();
  11.     } else {
  12.      window.opener =null; window.close();
  13.     }
  14.    }else{
  15.    window.close()
  16.    }
  17. }
复制代码





欢迎光临 站长论坛 (http://tzlink.com/bbs/) Powered by Discuz! X3.2