今天來說明一些跟瀏覽器有關的功能
window.screen.width 可直接寫 screen.width
document:之前在 DOM 已經說了不少screen:裝置的顯示相關,如 screen.width 可以知道目前裝置解析度的寬度location:網頁路徑相關,如 location.href 可以知道目前的網址路徑navigator:瀏覽器資訊相關,如 navigator.online 可以知道目前是否連線狀態history:瀏覽記錄相關,如 history.length 可以知道瀏覽記錄的筆數window.alert():跳出一個彈跳視窗window.open():開啟新的瀏覽器視窗window.print():開啟瀏覽器的列印功能src="" 連結記得移除)a.html
<body>
<div>
<a href="b.html">連到下一頁</a>
<input type="button" id="next" value="下一頁">
</div>
<script>
document.getElementById("next").onclick = function(){
window.history.forward();
};
// 找到 id = next 點擊時執行 history.forward()
</script>
</body>
b.html
<body>
<div>
<input type="button" id="back" value="上一頁">
</div>
<script>
document.getElementById("back").onclick = function(){
window.history.back();
};
// 找到 id = back 點擊時執行 history.back()
</script>
</body>
index.html
<body>
<input type="button" id="print" value="列印">
<input type="button" id="open" value="開新視窗">
<script src="JS/test.js"></script>
</body>
test.js
// 找到 id print 在點擊時開啟 列印功能
document.getElementById("print").onclick = function(){
window.print();
};
// 找到 id open 在點擊時開啟 新視窗
document.getElementById("open").onclick = function(){
window.open("https://www.google.com/");
};
預計進行 AJAX 的部分