1. 程式人生 > >自動識別PC端、移動端,並跳轉

自動識別PC端、移動端,並跳轉

PC端和移動端程式碼是分開的,各有一套程式碼的情況下:

在PC端的HTML檔案head標籤中間新增一段自動識別移動端的JavaScript程式碼:

<script type="text/javascript">
    if(/Android|webOS| iPhone | iPad | iPod |BlackBerry|opera mini|opera mobile|appleWebkit.*mobile|mobile/i.test(navigator.userAgent)) {
        window.location.replace("{{url('/wap/anti')}}");
    }
</script>