ila_rigo Posted June 4, 2021 Share Posted June 4, 2021 <!DOCTYPE html> <html> <body> <p>Display "iphone" if the outherWidth is equal or less than 320px</p> <p id="demo">desktop</p> <script> function checkOuterWidth(){ var w = window.outerWidth; if (w <= 320) { document.getElementById("demo").innerHTML = "iphone"; } else { document.getElementById("demo").innerHTML = "desktop"; } } </script> </body> </html> Hello, i am trying to write a function to detect the browser width and, based on that, have two different results. I have looked at some examples and tried to reproduce some tutorials but at the moment it doesn't work ... suggestions and corrections are very welcome Link to comment Share on other sites More sharing options...
Ingolme Posted June 5, 2021 Share Posted June 5, 2021 You have defined a function, but are not calling it. The code in a function only runs when the function is called. See the "function invocation" section in the Javascript tutorial: https://www.w3schools.com/js/js_functions.asp 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now