解决JavaScript页面刷新 与 弹出窗口问题 无提示关闭窗口

来源:互联网 发布:java递归用乌龟画属性 编辑:程序博客网 时间:2024/05/16 16:57
  1. 1.无提示刷新网页 
  2. 大家有没有发现,有些网页,刷新的时候,会弹出一个提示窗口,点“确定”才会刷新。 
  3. 而有的页面不会提示,不弹出提示窗口,直接就刷新了. 
  4. 如果页面没有form,则不会弹出提示窗口。如果页面有form表单, 
  5. a)< form method="post" ...> 会弹出提示窗口 
  6. b)< form method="get" ...> 不会弹出 
  7. 2.javascript刷新页面的方法 
  8. window.location.reload(); 
  9. 使用window.open()弹出的弹出窗口,刷新父窗口 
  10. window.opener.location.reload() 
  11. 使用window.showDialog弹出的模式窗口 
  12. window.dialogArguments.location.reload(); 
  13. 3.javascript弹出窗口代码 
  14. 下面给两个弹出屏幕居中窗口的例子 
  15. window.open()方式 
  16. function ShowDialog(url) { 
  17. var iWidth=300; //窗口宽度
  18. var iHeight=200;//窗口高度
  19. var iTop=(window.screen.height-iHeight)/2;
  20. var iLeft=(window.screen.width-iWidth)/2;
  21. window.open(
  22. url,"Detail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,
  23. Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft
  24. ); 
  25. }
  26. window.showModalDialog方式 
  27. function ShowDialog(url) { 
  28. var iWidth=300; //窗口宽度
  29. var iHeight=200;//窗口高度
  30. var iTop=(window.screen.height-iHeight)/2;
  31. var iLeft=(window.screen.width-iWidth)/2;
  32. window.showModalDialog(
  33. url,window,"dialogHeight: "+iHeight+"px;dialogWidth: "+iWidth+"px;
  34. dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:no"
  35. );
  36. }
  37. 注意这里的第二个参数,window 
  38. 4.模式窗口数据不刷新(缓存)问题 
  39. 在jsp页面加入如下语句 
  40. 5.模式窗口中,链接弹出新窗口问题 
  41. 在< /head >和< body >间加入< base target="_self" > 
  42. 6.无提示关闭页面的方法 
  43. function CloseWin(){ 
  44. var ua = navigator.userAgent; var ie = navigator.appName==
  45. "Microsoft Internet Explorer"?true:false
  46. if(ie){
  47. var IEversion = parseFloat(ua.substring(ua.indexOf("MSIE ")+5,
  48. ua.indexOf(";",ua.indexOf("MSIE ")))); 
  49. if( IEversion< 5.5){
  50. var str = ;
  51. document.body.insertAdjacentHTML("beforeEnd", str);
  52. document.all.noTipClose.Click(); 
  53. else {
  54. window.opener =null; window.close();
  55. }
  56. }else
  57. window.close() 
  58. }
  59. }