title: Javascript Screen Width/Media Query If Statement That Returns an Alert Box if True
body: <p>I am <em>very</em> new to Javascript and web development as a whole and I'm quite stuck with an If Statement here. The objective of this code is to read if the screen width (or media query) is below 450px, and if so display an alert box - I'm only needing this to work on one page at the moment.</p>
  
  <p>The HTML:</p>
  
  <pre><code>either
  
  &lt;body onload="fullQuote()"&gt;
  
  -or- (I'm not sure if the second actually works)
  
  &lt;script&gt;window.onload = fullQuote()&lt;/script&gt;
  </code></pre>
  
  <p>The JavaScript:</p>
  
  <pre><code>function fullQuote() {
  var mediaQuery = window.matchMedia("(max-width: 450px)");
  if (mediaQuery.matches) {
      alert("Test");
      }
  }
  </code></pre>
  
  <p>I can't seem to find an answer as to whats wrong with this code anywhere, but I have tried different methods of finding out the screen size like</p>
  
  <pre><code>if (screen.width &lt;= 450) {
  if (document.documentElement.clientWidth &lt; 450) {
  </code></pre>
  
  <p>and also a boolean within the if parentheses:</p>
  
  <pre><code>if (mediaQuery.matches == true) {
  </code></pre>
  
  <p>among some other ways around this now lost to memory which, of course, shared the same failed results.</p>
  
  <p>Any help to where I am going wrong this matter would be greatly appreciated,</p>
  
  <p>Thanks,</p>
  
  <p>Will</p>