0

Trying to write a function that will test conditions with certain browser window size using JavaScript. For example:

if ( window.width <= 500 && window.height <= 500){
do something ;
}else{
do something;

Are there any existing commands for JavaScript?

0

3 Answers 3

0

You can use window.innerWidth and window.innerHeight. Those should give you the viewport width and height respectively.

Sign up to request clarification or add additional context in comments.

Comments

0

In javascript, if you are running in a browser, you can use window.innerWidth and window.innerHeight, or also window.clientWidth and window.clientHeight.

There are little differences, you can read more about it here

Comments

0

Use window.screen.availHeight window.screen.availWidth and set them in variables to work with for example..

const height = window.screen.availHeight
const width window.screen.availWidth

if(width) {
do something}

1 Comment

Thank you. Can I set height and weight values to these commands? Or it's just returns value? What I'm trying to do is to write a script/condition to click on an element on a page. Element is visible when browser page in a small viewport. Like if width and height is "value", then click on element.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.