0

I have a website that I want to redirect on a particular page for mobile users, so the following is currently in the header of the relevant page

<script type="text/javascript">
if (screen.width<640) {
window.location="mobilePage";
}
</script>

If I click from the main navigation, this does nothing. However, I refresh the page, it works. Part of the trouble is that I've used a website builder, on account of not being any good at graphic design and not wanting to have to keep up with new phones / versions of things. That means a lot of code is hidden from me, which makes it phenomenally harder to debug. I've tried forcing it to reload once, but no dice.

Does anyone have any insight as to why this is happening, and more importantly if there's anything I can do? It would be much appreciated!

(PS Not sure if the website is helpful to elucidate my struggle, but the page in question is here.)

1 Answers1

-1

Instead of depending on the screen width, try using regex code and navigator. For Example,

  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
 window.location="mobilePage";
}

Hope this works

Manjunath PV
  • 326
  • 1
  • 2
  • 13
  • This is probably the worst advice you could follow. Don't do this. There are devices with these user agents that have regular sized screens. Likewise, there are devices not in your list that will have smaller screens. Don't do this. – Brad Nov 14 '17 at 05:45