您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

js判断是PC端还是移动端时一直刷新的解决方法

2024/2/26 14:04:23发布15次查看
本篇文章给大家带来的内容是关于js判断是pc端还是移动端时一直刷新的解决方法,文章介绍了对js中this的理解,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。
我在写官网的时候做了pc和移动端两个,在通过网上查找了这样的代码,看着完全没问题,等放进去页面中后,pc端页面一直刷新,根本停不下来,找了类似js还是同样的问题。通过不断尝试后才发现,问题就是多了一行代码:
原代码例子:
<script type="text/javascript">//平台、设备和操作系统var system = {win: false,mac: false,xll: false,ipad:false};//检测平台var p = navigator.platform;system.win = p.indexof(win) == 0;system.mac = p.indexof(mac) == 0;system.x11 = (p == x11) || (p.indexof(linux) == 0);system.ipad = (navigator.useragent.match(/ipad/i) != null)?true:false;//跳转语句,如果是手机访问就自动跳转到 里的页面if (system.win || system.mac || system.xll||system.ipad) {window.location.href =   pc端网站名 ;} else {window.location.href =  移动端端网站名   ;}</script>
修改后代码例子:
<script type="text/javascript">//平台、设备和操作系统var system = {win: false,mac: false,xll: false,ipad:false};//检测平台var p = navigator.platform;system.win = p.indexof(win) == 0;system.mac = p.indexof(mac) == 0;system.x11 = (p == x11) || (p.indexof(linux) == 0);system.ipad = (navigator.useragent.match(/ipad/i) != null)?true:false;//跳转语句,如果是手机访问就自动跳转到 里的页面if (system.win || system.mac || system.xll||system.ipad) { //window.location.href = pc端网站名;(在pc端引入js代码段时,这一行不能要,否则一直循环刷新,移动端同理)} else {window.location.href =  移动端端网站名   ;}</script>
相关推荐:
js判断是pc端还是移动端
js如何判断用户是在pc端和还是移动端访问_javascript技巧
以上就是js判断是pc端还是移动端时一直刷新的解决方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product