DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> JavaScript綜合知識 >> js實現跨窗體屏幕鎖定並彈出對話框
js實現跨窗體屏幕鎖定並彈出對話框
編輯:JavaScript綜合知識     

   function sAlert()

  {

  var msgw,msgh,bordercolor;

  msgw=450;

  msgh=120;

  titleheight=25;

  bordercolor = "#104E8B";

  var sWidth,sHeight;

  sWidth=screen.width; //取屏幕的寬和高。其他參數見文章屏幕寬高的取值

  sHeight=screen.height;

  var bgObj=window.parent.document.createElement("div");//創建一個元素,

  bgObj.setAttribute('id','bgDiv');

  bgObj.style.position="absolute";

  bgObj.style.top="0";

  bgObj.style.background="#cccccc";

  bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";

  bgObj.style.opacity="0.6";

  bgObj.style.filter = "alpha(opacity = 60)";

  bgObj.style.left="0";

  bgObj.style.width=sWidth + "px";

  bgObj.style.height=sHeight +"px";

  bgObj.style.zIndex = "10000"; /*設置對象bgObj即div的屬性,id,css屬性等*/

  window.parent.document.body.appendChild(bgObj); /*將bgObg這個對象加到父窗體上*/

  var msgObj=window.parent.document.createElement("div");

  msgObj.setAttribute("id","msgDiv");

  msgObj.setAttribute("align","center");

  msgObj.style.align = "center";

  msgObj.style.background="white";

  msgObj.style.border="1px solid " + bordercolor;

  msgObj.style.position = "absolute";

  msgObj.style.left = "50%%";

  msgObj.style.top = "50%%";

  msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";

  msgObj.style.marginLeft = "-225px" ;

  msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";

  msgObj.style.width = msgw + "px";

  msgObj.style.height =msgh + "px";

  msgObj.style.textAlign = "center";

  msgObj.style.lineHeight ="25px";

  msgObj.style.zIndex = "10001";

  var title=window.parent.document.createElement("h4");

  title.setAttribute("id","msgTitle");

  title.setAttribute("align","center");

  title.style.margin="0";

  title.style.padding="3px";

  title.style.background=bordercolor;

  title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,styl e=1,opacity=75,finishOpacity=100);

  title.style.opacity="0.75";

  title.style.border="1px solid " + bordercolor;

  title.style.height="18px";

  title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";

  title.style.color="white";

  title.style.cursor="pointer";

  title.innerHTML ='hello';

  window.parent.document.body.appendChild(msgObj);

  window.parent.document.getElementById("msgDiv").appendChild(title);

  }

  注意:

  1. 子窗體操作父窗體是,一定要在window後加上parent

  2.注意IE兼容性問題: a:調用createElement函數創建元素時,如果是加到 父窗體上的元素,創建時也要加上 window.parent.*.....因為IE浏覽器下 ,加到父窗體上的元素必須屬於父窗體。

  b:調用其中的函數,setAttribute()設置元素的屬性時,其實IE浏覽器支持這個函數,只是在用這個函數設置class屬性時,IE不支持,應該改用.設這相應的屬性。

  c:設置透明度這個屬性時, bgObj.style.opacity="0.6";

  bgObj.style.filter = "alpha(opacity = 60)";

  這兩行代碼 是設置一個屬性,第二種形式是為了兼容IE的透 明度屬性設置。

  具體這些屬性是什麼意思,可以參考一個比較棒的學習涉及web的語言的一個網站W3School:點擊打開鏈接

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved