-1

My intention is to redirect mobile devices from the standard mobile main page of blogger to another page made by myself for that purpose.

so I got this code and pasted on the head of the blogger theme template

<script>
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {window.location.replace("http://mysite.blogspot.com/page-for-mobile.html?m=1");
}
</script>

What it happens is that load endlessly I mean, I don't think that is some connection problem it's more like if starts the load again right before it finishes it.

Pablo Rojo
  • 31
  • 5

1 Answers1

1

This is because every time you enter the page the code runs and redirects the page.

I would suggest checking to see if you are already on that page or not.

UPDATED AGAIN

<script>
  if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) && window.location.href.indexOf('m=1') == -1){
    window.location.replace("http://mysite.blogspot.com/page-for-mobile.html?m=1");
  }
</script>
mc4future
  • 19
  • 3
  • sorry it keeps happening – Pablo Rojo Jun 24 '19 at 22:45
  • I just changed the code. Sorry I was lazy to double check my own code. It should be working considering the initial URL doesn't include the parameter "m=1" and after the first window.location.replace it will. – mc4future Jun 24 '19 at 22:53
  • Now it throws this error: "The entity name must immediately follow the '&' in the entity reference" on the line that contains the "&&" of course and it keeps happening the endless load – Pablo Rojo Jun 24 '19 at 23:38
  • @PabloRojo I updated the code again. I doubled checked it should work. – mc4future Jun 25 '19 at 17:32