window對象中 screenX screenY innerWidth的意義


1.screenX screenY 表示窗口相對於屏幕左上角的位置。注意IE不支持此屬性。 只讀屬性。

    IE 中的實現用screenLeft screenTop (等於screenY + 工具欄+菜單欄+地址欄的像素)

2.innerWidth innerHeight窗口中文檔顯示區域的寬度,不包括邊框和滾動條,該屬性可讀可寫。

IE8之前的瀏覽器不支持該屬性,IE中body元素的clientHeight屬性與該屬性相同。

clientHeight與clientWidth屬性是只讀的。

3.outerWidth表示窗口的寬度包括兩邊的border及滾動條的值, outerHeight 表示窗口的高度包括菜單,地址欄,工具欄等,屬性可讀性。

       IE8 之前的瀏覽器不支持,且沒有提供替代的屬性

4.pageXOffset 整數只讀屬性,表示文檔向右滾動過的像素數 pageYOffset 整數只讀屬性,表示文檔向下滾動過的像素數。

       IE8 之前的瀏覽器不支持,可以這樣實現。document.body.scrollLeft document.body.scrollTop

 

jpg

   測試代碼如下。

 

<html>
<head>
  <title>name</title>
</head>
<body>


<script>
   function openWin() {
      var myWindow = window.open('','_parent');
	  myWindow.document.write('<p style=""> this is my window </p>');
	  if(myWindow.screenX) {
	      myWindow.document.write('<br> screenX:' + myWindow.screenX);
	  } else if(myWindow.screenLeft) {
	     //IE
	      myWindow.document.write('<br> screenLeft:' + myWindow.screenLeft);
	  }
	  
	  if (myWindow.screenY) {
	      myWindow.document.write('<br> screenY:' + myWindow.screenY);
	  } else if(myWindow.screenTop) {
	      //IE
	      myWindow.document.write('<br> screenTop:' + myWindow.screenTop);
	  }
	  if(myWindow.innerWidth) {
	    myWindow.document.write('<br> innerWidth:' + myWindow.innerWidth);
	    myWindow.document.write('<br> innerHieght:' + myWindow.innerHeight);
	  } else {
	     //IE
	    myWindow.document.write('<br> innerWidth:' + myWindow.document.body.clientWidth);
	    myWindow.document.write('<br> innerHeight:' + myWindow.document.body.clientHeight);
	  }
	  if (myWindow.outerWidth) {
	     myWindow.document.write('<br> outerWidth:' + myWindow.outerWidth);
	     myWindow.document.write('<br> outerHeight:' + myWindow.outerHeight);
	  } else {
	     //IE not support
	  }
	  myWindow.scrollBy(100,100);
	  if (myWindow.pageXOffset) {
	     myWindow.document.write('<br> pageXOffset:' + myWindow.pageXOffset);
	  } else {
	     myWindow.document.write('<br/> scrollLeft:' + myWindow.document.body.scrollLeft);
	  }
	  if (myWindow.pageYOffset) {
	    myWindow.document.write('<br> pageYOffset:' + myWindow.pageYOffset);
	  } else {
             myWindow.document.write('<br/> scrollTop:' + myWindow.document.body.scrollTop);
	  }


   }

</script>
<a href="javascript:;" onclick="openWin()"> new window</a>
</body>

</html>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM