URL Redirect Based on Screen Length or height

So how to i get that code with length screen, can anyone help me. I try this code on the header and it doesn’t work:
“<script type=””text/javascript””> if (screen.length <= 1500) { window.location = “”https://www.google.com/””

I want a code can do it