本文目錄一覽:
- 1、一個JS檢測網頁窗口的高寬效果
- 2、網頁中如何用javascript識別本機是否已進入屏保或待機狀態
- 3、如何檢測網頁是否完全加載完成?包括引入的js和css
- 4、js怎樣檢測當前頁面是否有alert()彈出??
- 5、如何使用js檢測頁面上一個元素是否已經滾動到了屏幕的可視區域內
- 6、怎麼查看網頁打開時調用了哪些js?
一個JS檢測網頁窗口的高寬效果
form action=”#” method=”get” name=”form1″ id=”form1″
!–顯示瀏覽器窗口的實際尺寸–
瀏覽器窗口 的 實際高度: input type=”text” name=”availHeight” size=”4″/br /
瀏覽器窗口 的 實際寬度: input type=”text” name=”availWidth” size=”4″/br /
/form
script type=”text/javascript”
!–
var winWidth = 0;
var winHeight = 0;
function findDimensions() //函數:獲取尺寸
{
//獲取窗口寬度
if (window.innerWidth)
winWidth = window.innerWidth;
else if ((document.body) (document.body.clientWidth))
winWidth = document.body.clientWidth;
//獲取窗口高度
if (window.innerHeight)
winHeight = window.innerHeight;
else if ((document.body) (document.body.clientHeight))
winHeight = document.body.clientHeight;
//通過深入Document內部對body進行檢測,獲取窗口大小
if (document.documentElement document.documentElement.clientHeight document.documentElement.clientWidth)
{
winHeight = document.documentElement.clientHeight;
winWidth = document.documentElement.clientWidth;
}
//結果輸出至兩個文本框
document.form1.availHeight.value= winHeight;
document.form1.availWidth.value= winWidth;
}
findDimensions();
//調用函數,獲取數值
window.onresize=findDimensions;
//–
function set_wh(){
document.getElementById(‘my_tb’).width=document.form1.availHeight.value;
document.getElementById(‘my_tb’).height=document.form1.availWidth.value;
}
/script
table border=”1″ cellpadding=”0″ cellspacing=”0″ id=”my_tb”
trtd11/td/tr
/table
input type=”button” value=”設置表格的寬和高” onclick=”set_wh()”
網頁中如何用javascript識別本機是否已進入屏保或待機狀態
不可能,js無法檢測本地狀態,但可以檢測當前窗口是否失去焦點
如何檢測網頁是否完全加載完成?包括引入的js和css
按F12 比如Chrome瀏覽器 點擊network,如果網頁全部加載完成會顯示 調試框的最下面會顯示DOMContentLoaded 12s. 後面跟多少秒。是加載整個網頁使用的時間。
js怎樣檢測當前頁面是否有alert()彈出??
要檢測alert,只能修改window.alert。
參考修改方法如下:
script
var flag=true;//定義狀態標誌
var alertFun=window.alert;
window.alert=function(str)
{
flag=false;
alertFun(str);
};
document.write(flag);//alert之前
alert(“我現在alert”);
document.write(flag);//alert之後
/script
將標誌位設為數字的時候,可以統計alert的次數
如何使用js檢測頁面上一個元素是否已經滾動到了屏幕的可視區域內
var top = obj.getBoundingClientRect().top //元素頂端到可見區域頂端的距離
var se = document.documentElement.clientHeight //瀏覽器可見區域高度。
if(top = se ) {
//code
}
怎麼查看網頁打開時調用了哪些js?
需要準備的材料分別有:電腦、chrome瀏覽器。
1、首先,chrome瀏覽器,以zhidao.baidu.com為例,進入網頁。
2、鍵盤按F12,顯示出開發者工具面板,點擊“Network”的“JS”選項。
3、刷新頁面,此時會列出所有調用的js文件。
原創文章,作者:BARM,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/135371.html