0

I'm building one single page website and I want my page to load at some specific div depending if using normal computers or mobiles devices, all I have is:

<script type="text/javascript">
onload = function()
{location.href = "#home";}
</script>

The code seems to work fine but then I need to detect mobile device so page can scroll down to another div on load function, I have this code so far but I can't make it work:

<script type="text/javascript">
onload = function()
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/i)) 
{location.href = "#packages";}
</script>

How can I fix this and how can I put both codes together?

4

2 に答える 2

1

関数ブラケットを忘れました。

<script type="text/javascript">
    onload = function() {
        if (navigator.userAgent.match(/(iPod|iPhone|iPad)/i)) {
            location.href = "#packages";
        }
    }
</script>
于 2013-10-01T04:40:38.947 に答える
0

manishie のおかげで、両方のコードをまとめました (おそらく面倒ですが、すべてが機能しています!)

onload = function() {  
    if (navigator.userAgent.match(/(iPod|iPhone|iPad|Android|Blackberry)/i)) {
        location.href = "#mobile";
} 
else {
location.href = "#home";
}
} //end function
于 2013-10-01T15:40:48.830 に答える