| onload時点で画面サイズを取得 |
| window.onloadとDOMContentLoadedイベントの違い |
window.onload = function()
{
const width = window.innerWidth;
const height = window.innerHeight;
console.log("画面幅: " + width + "px, 画面の高さ: " + height + "px");
};
全ての処理が終わったあとで実行されます。
document.addEventListener('DOMContentLoaded', function()
{
const width = window.innerWidth;
const height = window.innerHeight;
console.log("画面幅: " + width + "px, 画面の高さ: " + height + "px");
});
HTMLの解析が完了し、DOMツリーが構築された時点で実行されます。| Get screen size at onload |
| Difference between window.onload and DOMContentLoaded events |
window.onload = function()
{
const width = window.innerWidth;
const height = window.innerHeight;
console.log("screen width: " + width + "px, screen height: " + height + "px");
};
It is executed after all processing is completed.
document.addEventListener('DOMContentLoaded', function()
{
const width = window.innerWidth;
const height = window.innerHeight;
console.log("screen width: " + width + "px, screen height: " + height + "px");
});
Executed when HTML parsing is complete and the DOM tree is constructed. | ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |