JS中获得窗口属性的方法

1。获得屏幕的分辨率:
screen.width
screen.height

2。获得窗口大小:
document.body.clientWidth
document.body.clientHeight

3。获得窗口大小(包含Border、Scroll等元素)
document.body.offsetWidth
document.body.offsetHeight


div相关的一些元素详细说明可以参考这张图


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 jQuery ,可以使用以下方法来获取父类窗口属性: 1. 在子类弹窗使用父类窗口的选择器来获取属性,例如: ``` class Parent { constructor() { this.attribute = "父类属性"; this.child_window = new Child(); } } class Child { constructor() { this.get_attribute(); } get_attribute() { let attribute = $(window.parent.document).find("#parent_window_id").data("attribute"); console.log(attribute); } } ``` 在这个例子,子类弹窗 Child 在初始化时调用 get_attribute 方法,该方法使用父类窗口的选择器 $(window.parent.document).find("#parent_window_id") 来获取父类窗口的某个元素,然后使用 jQuery 的 data 方法来获取该元素的 data 属性,从而获得父类窗口属性值。 2. 在父类窗口属性值保存在 cookie ,子类弹窗读取 cookie 来获取属性值,例如: ``` class Parent { constructor() { this.attribute = "父类属性"; document.cookie = "attribute=" + this.attribute; this.child_window = new Child(); } } class Child { constructor() { this.get_attribute(); } get_attribute() { let attribute = document.cookie.replace(/(?:(?:^|.*;\s*)attribute\s*\=\s*([^;]*).*$)|^.*$/, "$1"); console.log(attribute); } } ``` 在这个例子,父类窗口在初始化时把属性值保存在 cookie ,子类弹窗在初始化时调用 get_attribute 方法,该方法使用 JavaScript 的 document.cookie 属性来获取 cookie,然后使用正则表达式来从 cookie 字符串提取属性值,从而获得父类窗口属性值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值