web開發之瀏覽器(三)----瀏覽器常用事件及屬性

來源:互聯網
上載者:User

標籤:

瀏覽器頁面後退事件

<a href="javascript:history.back(-1)" class="btn btn-default" >返回</a>history.back(-1):直接返回當前頁的上一頁,資料全部訊息,是個新頁面history.go(-1):也是返回當前頁的上一頁,不過表單裡的資料全部還在history.back(0) 重新整理 history.back(1) 前進 history.back(-1) 後退 //希望最終停在B頁,不想點B頁瀏覽器返回按鈕,返回到A頁,則在A頁加:$(document).ready(function(){    window.history.forward(1);})

瀏覽器離開頁面或關閉選項卡提示

window.onbeforeunload = function(){return "Are you sure to leave?" ;//離開頁面提示}或者$(window).unload(function(){  alert("Goodbye!");});

瀏覽器進入頁面事件或者頁面載入完畢事件

window.onload = function(){}或$(function(){})注意:前者只能執行一次且必須等待頁面的所有元素全部載入完畢(包括圖片)才開始執行    後者可以執行多次,且只需要等待頁面架構dom結構下載完畢後就開始執行

瀏覽器捲軸事件

$(window).scrollTop();  //得到捲軸距離頂部的距離。  //設定捲軸距離頂部或底部的距離,保持捲軸狀態等$(window).scroll( function() {   var screenheight = window.screen.availHeight; //擷取螢幕高   $(window).scrollTop( document.body.clientHeight-120-screenheight);//保持捲軸距離底部120px  } );

瀏覽器網頁寬度等屬性

var s = "";    s += " 網頁可見地區寬:" + document.body.clientWidth + "\n";    s += " 網頁可見地區高:" + document.body.clientHeight + "\n";    s += " 網頁可見地區寬:" + document.body.offsetWidth + " (包括邊線和捲軸的寬)" + "\n";    s += " 網頁可見地區高:" + document.body.offsetHeight + " (包括邊線的寬)" + "\n";    s += " 網頁本文全文寬:" + document.body.scrollWidth + "\n";    s += " 網頁本文全文高:" + document.body.scrollHeight + "\n";    s += " 網頁被捲去的高(ff):" + document.body.scrollTop + "\n";    s += " 網頁被捲去的高(ie):" + document.documentElement.scrollTop + "\n";    s += " 網頁被捲去的左:" + document.body.scrollLeft + "\n";    s += " 網頁本文部分上:" + window.screenTop + "\n";    s += " 網頁本文部分左:" + window.screenLeft + "\n";    s += " 螢幕解析度的高:" + window.screen.height + "\n";    s += " 螢幕解析度的寬:" + window.screen.width + "\n";    s += " 螢幕可用工作區高度:" + window.screen.availHeight + "\n";    s += " 螢幕可用工作區寬度:" + window.screen.availWidth + "\n";    s += " 你的螢幕設定是 " + window.screen.colorDepth + " 位彩色" + "\n";    s += " 你的螢幕設定 " + window.screen.deviceXDPI + " 像素/英寸" + "\n";    alert(s);     某元素距離頂部距離document.getElementById(id).offset().top 某元素距離左邊距離document.getElementById(id).offset().left

瀏覽器調整視窗大小事件

window.onresize=function(){}或者$(window).resize(function(){     alert(‘window is resized !!‘);});


web開發之瀏覽器(三)----瀏覽器常用事件及屬性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.