<script> if (document.body.clientWidth>800){ document.write("<script>console.log('hello!');<\/script>"); } </script>
This is how it works. If the screen width is small, then there is no alert. If more than 800 pixels - an alert appears. It is necessary to screen a slash <\/script> . If it is not escaped, it does not work - the browser will think that the script is a piece of code:
<script> if (document.body.clientWidth>800){ document.write("<script>console.log('hello!');<\/script>
The idea that the script works with one width of the screen and does not work with the other is interesting.
As for availWidth, this is the width of the screen in general in pixels. it never changes if the monitor is not changed. you can use innerWidth and clientWidth. here is their description. https://learn.javascript.ru/metrics-window