Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript document.location redirect to a wrong url

I use this following code to redirect if site was visited on mobile devices

<script type="text/javascript">
<!--
if (screen.width <= 978) {
document.location = "mobile.mysite.com";
}
//-->
</script>

I tested it on many devices. Why does the site redirects to www.mysite.com/mobile.mysite.com instead of mobile.mysite.com only?

like image 925
Snippet Avatar asked Jul 11 '13 08:07

Snippet


1 Answers

Try this thing

<script type="text/javascript">
<!--
if (screen.width <= 978) {
document.location.href = "http://mobile.mysite.com";
}
//-->
</script>
like image 57
Adils Adils Avatar answered Oct 02 '22 18:10

Adils Adils