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);

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