JS中用window.open()方式打开,使新页面全屏、居中的代码

 

window.open()的介绍

1.基本语法  window.open(pageURL,name,parameters)

2.各项参数
其中yes/no也可使用1/0;pixel value为具体的数值,单位象素。

参数 | 取值范围 | 说明

alwaysLowered | yes/no | 指定窗口隐藏在所有窗口之后
alwaysRaised | yes/no | 指定窗口悬浮在所有窗口之上
depended | yes/no | 是否和父窗口同时关闭
directories | yes/no | Nav2和3的目录栏是否可见
height | pixel value | 窗口高度
hotkeys | yes/no | 在没菜单栏的窗口中设安全退出热键
innerHeight | pixel value | 窗口中文档的像素高度
innerWidth | pixel value | 窗口中文档的像素宽度
location | yes/no | 位置栏是否可见
menubar | yes/no | 菜单栏是否可见
outerHeight | pixel value | 设定窗口(包括装饰边框)的像素高度
outerWidth | pixel value | 设定窗口(包括装饰边框)的像素宽度
resizable | yes/no | 窗口大小是否可调整
screenX | pixel value | 窗口距屏幕左边界的像素长度
screenY | pixel value | 窗口距屏幕上边界的像素长度
scrollbars | yes/no | 窗口是否可有滚动栏
titlebar | yes/no | 窗口题目栏是否可见
toolbar | yes/no | 窗口工具栏是否可见
Width | pixel value | 窗口的像素宽度
z-look | yes/no | 窗口被激活后是否浮在其它窗口之上


---------------------------------------------------------------------------------------------------------

直接用法:

定义全局变量fullScreenFeatureList并赋值:

var fullScreenFeatureList = "left=0,top=0,screenX=0,screenY=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1";   

try { 
 if (window.screen) {
  var ah = screen.availHeight - 30;
  var aw = screen.availWidth - 10;
  fullScreenFeatureList += ",height=" + ah;
  fullScreenFeatureList += ",innerHeight=" + ah;
  fullScreenFeatureList += ",width=" + aw;
  fullScreenFeatureList += ",innerWidth=" + aw;
  fullScreenFeatureList += ",resizable";
 }
 else {
  fullScreenFeatureList += ",resizable";
 }
}
catch(e) {

}

在其他function中调用,直接用window.open()方式打开:

window.open("", "printPreview", fullScreenFeatureList);  // url可省略
form.action = "printPreview.asp";
form.target = "printPreview";   //给printPreview.asp页面做个标志,即使其他链接跳转到该页面,也仅仅是内容重新载入而不会重开一个页面
form.submit();


---------------------------------------------------------------------------------------------------------

全屏JS代码
function fullScreenWindowNamed(url, windowName, fullScreenFeatureList, returnWindowHandle) {
 
 if(!fullScreenFeatureList)
 {
  fullScreenFeatureList = "left=0,top=0,screenX=0,screenY=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1";  
 }

 try { 
  if (window.screen) {
   var ah = screen.availHeight - 30;
   var aw = screen.availWidth - 10;
   fullScreenFeatureList += ",height=" + ah;
   fullScreenFeatureList += ",innerHeight=" + ah;
   fullScreenFeatureList += ",width=" + aw;
   fullScreenFeatureList += ",innerWidth=" + aw;
   fullScreenFeatureList += ",resizable";
  }
  else {
   fullScreenFeatureList += ",resizable";
  }
 }
 catch(e) {

 }

 var link = window.open("", "printPreview", fullScreenFeatureList);
 if(returnWindowHandle)
 {
  return link;
 }
}


---------------------------------------------------------------------------------------------------------


居中JS代码

function centeredWindowNamed(url, windowName, popW, popH, featureList, returnWindowHandle) {

 if(!featureList)
 {
  featureList = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
 }
 var w = 800, h = 600;
  
 try {
  if(screen.availWidth) {
     w = screen.availWidth;
     h = screen.availHeight;
  }
 }
 catch(e) {}

 var leftPos = (w-popW)/2;
 var topPos = (h-popH)/2;
 
 var link = window.open(url, windowName, featureList + ",width=" + popW + ",height=" + popH + ",top=" + topPos + ",left=" + leftPos);
 try {
  link.focus();
 }
 catch(e) {}
 
 if(returnWindowHandle)
 {
  return link;
 }
}


centeredWindowNamed("printPreview.asp", "printPreview", 800, 600);

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章