• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. javascript學(xué)習(xí)筆記:window對象使用介紹

        時間:2024-11-03 00:36:30 JavaScript 我要投稿
        • 相關(guān)推薦

        javascript學(xué)習(xí)筆記:window對象使用介紹

          1.窗口位置

        javascript學(xué)習(xí)筆記:window對象使用介紹

          以下取得瀏覽器窗口距屏幕左邊和上邊的位置

          復(fù)制代碼 代碼如下:

          var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft : window.screenX; //左邊位置

          var topPos = (typeof window.screenTop == "number") ? window.screenTop : window.screenY; //上邊位置

          2.瀏覽器大小

          以下取得瀏覽器頁面視口的大小

          復(fù)制代碼 代碼如下:

          var pageWidth = window.innerWidth,

          pageHeight = window.innerHeight;

          if (typeof pageWidth != "number") {

          if (document.compatMode == "CSS1Compat") {

          pageWidth = document.documentElement.clientWidth;

          pageHeight = document.documentElement.clientHeight;

          } else {

          pageWith = document.body.clientWdith;

          pageHeight = document.body.clientHeight;

          }

          }

          3.打開或彈出窗口

          window.open()方法,可以接受4個參數(shù),通常只需指定第一個參數(shù),第一個參數(shù)為URL,第二個參數(shù)為_self 、_parent 、_top 、_blank 或者框架名

          復(fù)制代碼 代碼如下:

          window.open("http://www.baidu.com");

          window.open("http://www.baidu.com","_blank");

          window.open("http://www.baidu.com","topFrame","height=400,width=400,top=10,left=10,resizable = yes");

          topFrame.resizeTo(500,300); //調(diào)整窗口大小

          topFrame.moveTo(100,100); //移動窗口位置

          topFrame.close(); //關(guān)閉新打開的窗口,IE會報錯

          4.location 對象

          location.href(URL) 加載URL

          復(fù)制代碼 代碼如下:

          location.href(URL) 加載URL

          location.href("http://www.baidu.com");

          location.href = "http://www.baidu.com" ; //同上

          location.assign = "http://www.baidu.com"; //同上

          window.loaction = "http://www.baidu.com"; //同上

          location.replace("http://www.baidu.com"); //同上,但不能回退

          location.reload(); //重新加載(可能從緩存中加載)

          location.reload(true); //重新加載(從服務(wù)器中加載)

          location.search() 返回URL中的查詢字符串,字符串以為?開頭

          5.獲取查詢字符串參數(shù)

          復(fù)制代碼 代碼如下:

          function getQueryStringArgs() {

          var qs = (location.search.length > 0) location.search.substring(1) : "";

          var args ={};

          var items = qs.split("&");

          var item = null,name = null,value = null;

          for (var i=0 ; i<items.length ; i++)

          {

          item = itmes[i].split("=");

          name = decodeURIComponent(item[0]);

          value = decodeURIComponent(item[1]);

          args[name] = value;

          }

          return args;

          }

          //假設(shè)查詢字符串參數(shù)是?q=javascript&num=10

          var args = getQueryStringArgs();

          alert(args["q"]); //"javascript"

          alert(args["num"]); //"10"

          6.history 對象

          復(fù)制代碼 代碼如下:

          history.go()頁面跳轉(zhuǎn)

          history.go(-1); //后退一頁

          history.go(1); //前進(jìn)一頁

          history.go(2); //前進(jìn)兩頁

          history.go("baidu.com"); 跳轉(zhuǎn)到最近的baidu.com頁面

          history.back(); //后退一頁

          history.forword(); //前進(jìn)一頁

          檢測當(dāng)前頁是不是用戶打開的第一個頁面

          復(fù)制代碼 代碼如下:

          if (history.length == 0) {

          //如果打開的是第一個頁面的話,執(zhí)行某些操作

          }

          7.頁面加載

          window.onload() 用于頁面加載結(jié)束后做某些操作

          復(fù)制代碼 代碼如下:

          window.onload = function () {

          //執(zhí)行某些操作

          }

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

        【javascript學(xué)習(xí)筆記:window對象使用介紹】相關(guān)文章:

        使用ajax操作JavaScript對象的方法09-28

        JavaScript學(xué)習(xí)筆記08-24

        javascript克隆對象深度介紹07-25

        關(guān)于javascript對象之內(nèi)置和對象Math的使用方法10-08

        Javascript中arguments對象的詳解和使用方法08-20

        關(guān)于數(shù)據(jù)類型的Javascript學(xué)習(xí)筆記08-05

        JavaScript中的三種對象10-24

        整理Javascript基礎(chǔ)語法學(xué)習(xí)筆記欣賞08-04

        JavaScript高級程序設(shè)計:本地對象Array10-22

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 网址你懂的免费在线观看 | 日韩性色一区二区三区 | 制服丝袜中文字幕有码中出 | 最新国产精品第二页 | 日韩AVAV天堂AV在线 | 一级电影在线亚洲 |

            javascript學(xué)習(xí)筆記:window對象使用介紹

              1.窗口位置

            javascript學(xué)習(xí)筆記:window對象使用介紹

              以下取得瀏覽器窗口距屏幕左邊和上邊的位置

              復(fù)制代碼 代碼如下:

              var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft : window.screenX; //左邊位置

              var topPos = (typeof window.screenTop == "number") ? window.screenTop : window.screenY; //上邊位置

              2.瀏覽器大小

              以下取得瀏覽器頁面視口的大小

              復(fù)制代碼 代碼如下:

              var pageWidth = window.innerWidth,

              pageHeight = window.innerHeight;

              if (typeof pageWidth != "number") {

              if (document.compatMode == "CSS1Compat") {

              pageWidth = document.documentElement.clientWidth;

              pageHeight = document.documentElement.clientHeight;

              } else {

              pageWith = document.body.clientWdith;

              pageHeight = document.body.clientHeight;

              }

              }

              3.打開或彈出窗口

              window.open()方法,可以接受4個參數(shù),通常只需指定第一個參數(shù),第一個參數(shù)為URL,第二個參數(shù)為_self 、_parent 、_top 、_blank 或者框架名

              復(fù)制代碼 代碼如下:

              window.open("http://www.baidu.com");

              window.open("http://www.baidu.com","_blank");

              window.open("http://www.baidu.com","topFrame","height=400,width=400,top=10,left=10,resizable = yes");

              topFrame.resizeTo(500,300); //調(diào)整窗口大小

              topFrame.moveTo(100,100); //移動窗口位置

              topFrame.close(); //關(guān)閉新打開的窗口,IE會報錯

              4.location 對象

              location.href(URL) 加載URL

              復(fù)制代碼 代碼如下:

              location.href(URL) 加載URL

              location.href("http://www.baidu.com");

              location.href = "http://www.baidu.com" ; //同上

              location.assign = "http://www.baidu.com"; //同上

              window.loaction = "http://www.baidu.com"; //同上

              location.replace("http://www.baidu.com"); //同上,但不能回退

              location.reload(); //重新加載(可能從緩存中加載)

              location.reload(true); //重新加載(從服務(wù)器中加載)

              location.search() 返回URL中的查詢字符串,字符串以為?開頭

              5.獲取查詢字符串參數(shù)

              復(fù)制代碼 代碼如下:

              function getQueryStringArgs() {

              var qs = (location.search.length > 0) location.search.substring(1) : "";

              var args ={};

              var items = qs.split("&");

              var item = null,name = null,value = null;

              for (var i=0 ; i<items.length ; i++)

              {

              item = itmes[i].split("=");

              name = decodeURIComponent(item[0]);

              value = decodeURIComponent(item[1]);

              args[name] = value;

              }

              return args;

              }

              //假設(shè)查詢字符串參數(shù)是?q=javascript&num=10

              var args = getQueryStringArgs();

              alert(args["q"]); //"javascript"

              alert(args["num"]); //"10"

              6.history 對象

              復(fù)制代碼 代碼如下:

              history.go()頁面跳轉(zhuǎn)

              history.go(-1); //后退一頁

              history.go(1); //前進(jìn)一頁

              history.go(2); //前進(jìn)兩頁

              history.go("baidu.com"); 跳轉(zhuǎn)到最近的baidu.com頁面

              history.back(); //后退一頁

              history.forword(); //前進(jìn)一頁

              檢測當(dāng)前頁是不是用戶打開的第一個頁面

              復(fù)制代碼 代碼如下:

              if (history.length == 0) {

              //如果打開的是第一個頁面的話,執(zhí)行某些操作

              }

              7.頁面加載

              window.onload() 用于頁面加載結(jié)束后做某些操作

              復(fù)制代碼 代碼如下:

              window.onload = function () {

              //執(zhí)行某些操作

              }