Web*_*doz 2 javascript mobile redirect
嗨,这已经开始了几天了,我想重定向到移动网站,以便从屏幕宽度低于699的设备检查网站.我使用此脚本进行重定向:
<script type="text/javascript">
<!--
if (screen.width <= 699) {
window.location = "http://www.mywebsite.com.au/mobile/";
}
//-->
</script>
Run Code Online (Sandbox Code Playgroud)
当我通过Firefox检查网站但没有在Dolphin浏览器中工作时,脚本工作正常.
它可能只是我的手机,我有一个Galaxy S2.
提前感谢任何可以帮助我的人,我真的很感激!
新更新:-----确定这非常有趣.当我将屏幕宽度减小到599时,脚本在Dolpin浏览器中工作.(screen.width <= 599)---
我建议使用用户代理检测这样的东西
var isMobile = function() {
//console.log("Navigator: " + navigator.userAgent);
return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
};
Run Code Online (Sandbox Code Playgroud)
像这样重定向
if(isMobile()) {
window.location.href = "http://www.mywebsite.com.au/mobile/";
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6994 次 |
最近记录: |