Javascript - Run my script only if landscape is detectedCreate GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
Which creature is depicted in this Xanathar's Guide illustration?
The difference between きわめて and いたって
What was Varys trying to do at the beginning of S08E05?
Why doesn't Iron Man's action affect this person in Endgame?
How do I know which cipher suites can be disabled?
Why when I add jam to my tea it stops producing thin "membrane" on top?
Proper way to use apply_filters() with class functions?
What color to choose as "danger" if the main color of my app is red
Why are goodwill impairments on the statement of cash-flows of GE?
Will the volt, ampere, ohm or other electrical units change on May 20th, 2019?
tikz drawing rectangle discretized with triangle lattices and its centroids
Will British Airways compensate if my entertainment screen was defective for an entire flight?
Were any toxic metals used in the International Space Station?
Can my American children re-enter the USA by International flight with a passport card? Being that their passport book has expired
Who commanded or executed this action in Game of Thrones S8E5?
Does addError() work outside of triggers?
Why do galaxies collide
When is the AS keyword required?
Does the wearer know what items are in which patch in the Robe of Useful items?
Can anyone give me examples of the relative-determinative 'which'?
Is there any deeper thematic meaning to the white horse that Arya finds in The Bells (S08E05)?
Is there an academic word that means "to split hairs over"?
Could there be something like aerobatic smoke trails in the vacuum of space?
Do crew rest seats count towards the maximum allowed number of seats per flight attendant?
Javascript - Run my script only if landscape is detected
Create GUID / UUID in JavaScript?How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I remove a property from a JavaScript object?Which equals operator (== vs ===) should be used in JavaScript comparisons?How do I include a JavaScript file in another JavaScript file?What does “use strict” do in JavaScript, and what is the reasoning behind it?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am running a script to show a notification within a menu with scroll, but I do not know how to detect if the device has orientation landscape to validate the script.
The call onClick="VerHayMas();" works perfectly, but if the user open the menu once, clicking on #boton-menu and with your device in portrait, after changing the orientation to landscape the script no longer meet the objective.
The script has its logic ONLY if the device is in landscape, which is
when the menu needs to show the notification.
So, is it possible that my script is only valid with (max-width:999px) and (orientation:landscape), ignoring the portrait...?
I am a beginner in JS, and I do not know how to do it, really.
Any idea?
Thanks in advance!
HTML & CSS
#mas-menu display:none
<div id="boton-menu" onClick="VerHayMas();">+</div>
Script:
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
EDIT:
I have tried with the following script, but it does not work. If the user makes a call to onClick="VerHayMas();" in portrait mode, the script is no longer running in landscape mode.
What am I doing wrong here?
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas +1;
if(clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
,4000);
;
javascript jquery
add a comment |
I am running a script to show a notification within a menu with scroll, but I do not know how to detect if the device has orientation landscape to validate the script.
The call onClick="VerHayMas();" works perfectly, but if the user open the menu once, clicking on #boton-menu and with your device in portrait, after changing the orientation to landscape the script no longer meet the objective.
The script has its logic ONLY if the device is in landscape, which is
when the menu needs to show the notification.
So, is it possible that my script is only valid with (max-width:999px) and (orientation:landscape), ignoring the portrait...?
I am a beginner in JS, and I do not know how to do it, really.
Any idea?
Thanks in advance!
HTML & CSS
#mas-menu display:none
<div id="boton-menu" onClick="VerHayMas();">+</div>
Script:
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
EDIT:
I have tried with the following script, but it does not work. If the user makes a call to onClick="VerHayMas();" in portrait mode, the script is no longer running in landscape mode.
What am I doing wrong here?
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas +1;
if(clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
,4000);
;
javascript jquery
1
You can get the width and height of a window withwindow.innerHeightandwindow.innerWidthrespectively. How about keep it simple, if height is less than width, the user is in landscape mode.
– Alicia
May 4 at 0:21
If you simply want to hide something on landscape orientation, why not use one line of CSS?
– Salman A
May 4 at 12:58
Your attempt at putting the function declaration inside theifstatement does not work because then it is no longer a global that can be called from the inline event handler attribute.
– Bergi
May 4 at 13:07
add a comment |
I am running a script to show a notification within a menu with scroll, but I do not know how to detect if the device has orientation landscape to validate the script.
The call onClick="VerHayMas();" works perfectly, but if the user open the menu once, clicking on #boton-menu and with your device in portrait, after changing the orientation to landscape the script no longer meet the objective.
The script has its logic ONLY if the device is in landscape, which is
when the menu needs to show the notification.
So, is it possible that my script is only valid with (max-width:999px) and (orientation:landscape), ignoring the portrait...?
I am a beginner in JS, and I do not know how to do it, really.
Any idea?
Thanks in advance!
HTML & CSS
#mas-menu display:none
<div id="boton-menu" onClick="VerHayMas();">+</div>
Script:
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
EDIT:
I have tried with the following script, but it does not work. If the user makes a call to onClick="VerHayMas();" in portrait mode, the script is no longer running in landscape mode.
What am I doing wrong here?
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas +1;
if(clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
,4000);
;
javascript jquery
I am running a script to show a notification within a menu with scroll, but I do not know how to detect if the device has orientation landscape to validate the script.
The call onClick="VerHayMas();" works perfectly, but if the user open the menu once, clicking on #boton-menu and with your device in portrait, after changing the orientation to landscape the script no longer meet the objective.
The script has its logic ONLY if the device is in landscape, which is
when the menu needs to show the notification.
So, is it possible that my script is only valid with (max-width:999px) and (orientation:landscape), ignoring the portrait...?
I am a beginner in JS, and I do not know how to do it, really.
Any idea?
Thanks in advance!
HTML & CSS
#mas-menu display:none
<div id="boton-menu" onClick="VerHayMas();">+</div>
Script:
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
EDIT:
I have tried with the following script, but it does not work. If the user makes a call to onClick="VerHayMas();" in portrait mode, the script is no longer running in landscape mode.
What am I doing wrong here?
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
var clicksVerHayMas = 0;
function VerHayMas()
clicksVerHayMas = clicksVerHayMas +1;
if(clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
,4000);
;
javascript jquery
javascript jquery
edited May 4 at 0:59
Pablo_Web
asked May 4 at 0:14
Pablo_WebPablo_Web
1268
1268
1
You can get the width and height of a window withwindow.innerHeightandwindow.innerWidthrespectively. How about keep it simple, if height is less than width, the user is in landscape mode.
– Alicia
May 4 at 0:21
If you simply want to hide something on landscape orientation, why not use one line of CSS?
– Salman A
May 4 at 12:58
Your attempt at putting the function declaration inside theifstatement does not work because then it is no longer a global that can be called from the inline event handler attribute.
– Bergi
May 4 at 13:07
add a comment |
1
You can get the width and height of a window withwindow.innerHeightandwindow.innerWidthrespectively. How about keep it simple, if height is less than width, the user is in landscape mode.
– Alicia
May 4 at 0:21
If you simply want to hide something on landscape orientation, why not use one line of CSS?
– Salman A
May 4 at 12:58
Your attempt at putting the function declaration inside theifstatement does not work because then it is no longer a global that can be called from the inline event handler attribute.
– Bergi
May 4 at 13:07
1
1
You can get the width and height of a window with
window.innerHeight and window.innerWidth respectively. How about keep it simple, if height is less than width, the user is in landscape mode.– Alicia
May 4 at 0:21
You can get the width and height of a window with
window.innerHeight and window.innerWidth respectively. How about keep it simple, if height is less than width, the user is in landscape mode.– Alicia
May 4 at 0:21
If you simply want to hide something on landscape orientation, why not use one line of CSS?
– Salman A
May 4 at 12:58
If you simply want to hide something on landscape orientation, why not use one line of CSS?
– Salman A
May 4 at 12:58
Your attempt at putting the function declaration inside the
if statement does not work because then it is no longer a global that can be called from the inline event handler attribute.– Bergi
May 4 at 13:07
Your attempt at putting the function declaration inside the
if statement does not work because then it is no longer a global that can be called from the inline event handler attribute.– Bergi
May 4 at 13:07
add a comment |
2 Answers
2
active
oldest
votes
You can solve this using matchMedia:
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
// do something
Make sure to note the browser support in the MDN link.
EDIT TO PROVIDE CONTEXT:
Because the user may be moving around their screen, you will want to make this evaluation inside VerHayMas, each time it is run, to determine if the main body of the script should be executed:
var clicksVerHayMas = 0;
function VerHayMas()
var isLandscapeAndMeetsSizeRequirements = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (isLandscapeAndMeetsSizeRequirements)
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
So VerHayMas will be run on every click, but only if the screen meets the requirements as determined by the media query string will it execute the code inside the if block.
1
Couldn't you simply run thatmatchMediainside ofVeryHayMasso that it evaluates the screen size and orientation immediately before it needs to act on that information? Of course there orientation may change, so you will need to run it each time you make the check.
– Alexander Nied
May 4 at 1:07
@Pablo_Web - Updated answer with an example showing how this would work.
– Alexander Nied
May 4 at 1:21
Alexander Nied ... Now I understand. I was doing it wrong. I will study your script. It is very clean and tidy. Thank you!. Greetings...
– Pablo_Web
May 4 at 1:27
add a comment |
I'd keep it simple, if screen height is less than width, then the user is in landscape mode. You can grab the height and width from the global window object.
if (window.innerWidth > window.innerHeight)
// The user is in landscape mode!
userInLanscapeFunc();
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
2
Maybe it would be better to usescreen.width/.heightthough it depends if they actually care about the shape of the available window area or the screen orientation
– ᆼᆺᆼ
May 4 at 0:29
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55978407%2fjavascript-run-my-script-only-if-landscape-is-detected%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can solve this using matchMedia:
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
// do something
Make sure to note the browser support in the MDN link.
EDIT TO PROVIDE CONTEXT:
Because the user may be moving around their screen, you will want to make this evaluation inside VerHayMas, each time it is run, to determine if the main body of the script should be executed:
var clicksVerHayMas = 0;
function VerHayMas()
var isLandscapeAndMeetsSizeRequirements = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (isLandscapeAndMeetsSizeRequirements)
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
So VerHayMas will be run on every click, but only if the screen meets the requirements as determined by the media query string will it execute the code inside the if block.
1
Couldn't you simply run thatmatchMediainside ofVeryHayMasso that it evaluates the screen size and orientation immediately before it needs to act on that information? Of course there orientation may change, so you will need to run it each time you make the check.
– Alexander Nied
May 4 at 1:07
@Pablo_Web - Updated answer with an example showing how this would work.
– Alexander Nied
May 4 at 1:21
Alexander Nied ... Now I understand. I was doing it wrong. I will study your script. It is very clean and tidy. Thank you!. Greetings...
– Pablo_Web
May 4 at 1:27
add a comment |
You can solve this using matchMedia:
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
// do something
Make sure to note the browser support in the MDN link.
EDIT TO PROVIDE CONTEXT:
Because the user may be moving around their screen, you will want to make this evaluation inside VerHayMas, each time it is run, to determine if the main body of the script should be executed:
var clicksVerHayMas = 0;
function VerHayMas()
var isLandscapeAndMeetsSizeRequirements = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (isLandscapeAndMeetsSizeRequirements)
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
So VerHayMas will be run on every click, but only if the screen meets the requirements as determined by the media query string will it execute the code inside the if block.
1
Couldn't you simply run thatmatchMediainside ofVeryHayMasso that it evaluates the screen size and orientation immediately before it needs to act on that information? Of course there orientation may change, so you will need to run it each time you make the check.
– Alexander Nied
May 4 at 1:07
@Pablo_Web - Updated answer with an example showing how this would work.
– Alexander Nied
May 4 at 1:21
Alexander Nied ... Now I understand. I was doing it wrong. I will study your script. It is very clean and tidy. Thank you!. Greetings...
– Pablo_Web
May 4 at 1:27
add a comment |
You can solve this using matchMedia:
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
// do something
Make sure to note the browser support in the MDN link.
EDIT TO PROVIDE CONTEXT:
Because the user may be moving around their screen, you will want to make this evaluation inside VerHayMas, each time it is run, to determine if the main body of the script should be executed:
var clicksVerHayMas = 0;
function VerHayMas()
var isLandscapeAndMeetsSizeRequirements = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (isLandscapeAndMeetsSizeRequirements)
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
So VerHayMas will be run on every click, but only if the screen meets the requirements as determined by the media query string will it execute the code inside the if block.
You can solve this using matchMedia:
const matchesMediaQuery = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (matchesMediaQuery)
// do something
Make sure to note the browser support in the MDN link.
EDIT TO PROVIDE CONTEXT:
Because the user may be moving around their screen, you will want to make this evaluation inside VerHayMas, each time it is run, to determine if the main body of the script should be executed:
var clicksVerHayMas = 0;
function VerHayMas()
var isLandscapeAndMeetsSizeRequirements = window.matchMedia('(max-width:999px) and (orientation:landscape)').matches;
if (isLandscapeAndMeetsSizeRequirements)
clicksVerHayMas = clicksVerHayMas + 1;
if (clicksVerHayMas == 1)
document.getElementById('mas-menu').style.display = 'block';
window.setTimeout(function()
$('#mas-menu').fadeOut('slow');
, 4000);
;
So VerHayMas will be run on every click, but only if the screen meets the requirements as determined by the media query string will it execute the code inside the if block.
edited May 4 at 1:21
answered May 4 at 0:23
Alexander NiedAlexander Nied
4,41211130
4,41211130
1
Couldn't you simply run thatmatchMediainside ofVeryHayMasso that it evaluates the screen size and orientation immediately before it needs to act on that information? Of course there orientation may change, so you will need to run it each time you make the check.
– Alexander Nied
May 4 at 1:07
@Pablo_Web - Updated answer with an example showing how this would work.
– Alexander Nied
May 4 at 1:21
Alexander Nied ... Now I understand. I was doing it wrong. I will study your script. It is very clean and tidy. Thank you!. Greetings...
– Pablo_Web
May 4 at 1:27
add a comment |
1
Couldn't you simply run thatmatchMediainside ofVeryHayMasso that it evaluates the screen size and orientation immediately before it needs to act on that information? Of course there orientation may change, so you will need to run it each time you make the check.
– Alexander Nied
May 4 at 1:07
@Pablo_Web - Updated answer with an example showing how this would work.
– Alexander Nied
May 4 at 1:21
Alexander Nied ... Now I understand. I was doing it wrong. I will study your script. It is very clean and tidy. Thank you!. Greetings...
– Pablo_Web
May 4 at 1:27
1
1
Couldn't you simply run that
matchMedia inside of VeryHayMas so that it evaluates the screen size and orientation immediately before it needs to act on that information? Of course there orientation may change, so you will need to run it each time you make the check.– Alexander Nied
May 4 at 1:07
Couldn't you simply run that
matchMedia inside of VeryHayMas so that it evaluates the screen size and orientation immediately before it needs to act on that information? Of course there orientation may change, so you will need to run it each time you make the check.– Alexander Nied
May 4 at 1:07
@Pablo_Web - Updated answer with an example showing how this would work.
– Alexander Nied
May 4 at 1:21
@Pablo_Web - Updated answer with an example showing how this would work.
– Alexander Nied
May 4 at 1:21
Alexander Nied ... Now I understand. I was doing it wrong. I will study your script. It is very clean and tidy. Thank you!. Greetings...
– Pablo_Web
May 4 at 1:27
Alexander Nied ... Now I understand. I was doing it wrong. I will study your script. It is very clean and tidy. Thank you!. Greetings...
– Pablo_Web
May 4 at 1:27
add a comment |
I'd keep it simple, if screen height is less than width, then the user is in landscape mode. You can grab the height and width from the global window object.
if (window.innerWidth > window.innerHeight)
// The user is in landscape mode!
userInLanscapeFunc();
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
2
Maybe it would be better to usescreen.width/.heightthough it depends if they actually care about the shape of the available window area or the screen orientation
– ᆼᆺᆼ
May 4 at 0:29
add a comment |
I'd keep it simple, if screen height is less than width, then the user is in landscape mode. You can grab the height and width from the global window object.
if (window.innerWidth > window.innerHeight)
// The user is in landscape mode!
userInLanscapeFunc();
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
2
Maybe it would be better to usescreen.width/.heightthough it depends if they actually care about the shape of the available window area or the screen orientation
– ᆼᆺᆼ
May 4 at 0:29
add a comment |
I'd keep it simple, if screen height is less than width, then the user is in landscape mode. You can grab the height and width from the global window object.
if (window.innerWidth > window.innerHeight)
// The user is in landscape mode!
userInLanscapeFunc();
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
I'd keep it simple, if screen height is less than width, then the user is in landscape mode. You can grab the height and width from the global window object.
if (window.innerWidth > window.innerHeight)
// The user is in landscape mode!
userInLanscapeFunc();
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/innerHeight
answered May 4 at 0:24
AliciaAlicia
1,87422138
1,87422138
2
Maybe it would be better to usescreen.width/.heightthough it depends if they actually care about the shape of the available window area or the screen orientation
– ᆼᆺᆼ
May 4 at 0:29
add a comment |
2
Maybe it would be better to usescreen.width/.heightthough it depends if they actually care about the shape of the available window area or the screen orientation
– ᆼᆺᆼ
May 4 at 0:29
2
2
Maybe it would be better to use
screen.width/.height though it depends if they actually care about the shape of the available window area or the screen orientation– ᆼᆺᆼ
May 4 at 0:29
Maybe it would be better to use
screen.width/.height though it depends if they actually care about the shape of the available window area or the screen orientation– ᆼᆺᆼ
May 4 at 0:29
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55978407%2fjavascript-run-my-script-only-if-landscape-is-detected%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can get the width and height of a window with
window.innerHeightandwindow.innerWidthrespectively. How about keep it simple, if height is less than width, the user is in landscape mode.– Alicia
May 4 at 0:21
If you simply want to hide something on landscape orientation, why not use one line of CSS?
– Salman A
May 4 at 12:58
Your attempt at putting the function declaration inside the
ifstatement does not work because then it is no longer a global that can be called from the inline event handler attribute.– Bergi
May 4 at 13:07