怎麼從www跳轉到m,並不改變後續網址內容

廢話不多說,直接上代碼

<script>
var __current_url_4_forward = window.location.href;
var __ua__4_forward=window.navigator.userAgent.toLowerCase();
if(__ua__4_forward.toLowerCase().indexOf("android")!=-1 || __ua__4_forward.toLowerCase().indexOf("iphone")!=-1 ||__ua__4_forward.toLowerCase().indexOf("ipad")!=-1 || __ua__4_forward.toLowerCase().indexOf("windows mobile")!=-1){
    window.location.href = window.location.href.replace("cbook","mbook").replace("ccls","mcls").replace("https://www.","https://m.");
}
</script>

最後面的window.location.href.replace(“cbook”,”mbook”).replace(“ccls”,”mcls”).replace(“https://www.”,”https://m.”);可以考慮增添,方便運行

發布者:彬彬筆記,轉載請註明出處:https://www.binbinbiji.com/zh-hant/html5/2228.html

(1)
彬彬筆記彬彬筆記
上一篇 2021年3月7日
下一篇 2021年5月31日

相關推薦

發表回復

登錄後才能評論
蜀ICP備14017386號-13