首页 > 其他分享 >js判断手机访问并跳转移动端网址

js判断手机访问并跳转移动端网址

时间:2023-10-15 15:01:00浏览次数:30  
标签:murl PC replace 网址 跳转 js aspx

 1 <script type="text/javascript">
 2         function uaredirect(murl) {
 3             try {
 4                 if (document.getElementById("bdmark") != null) {
 5                     return;
 6                 }
 7                 var urlhash = window.location.hash;
 8                 if (!urlhash.match("fromapp")) {
 9                     if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
10                         murl = murl.replace("/ask/", "/touch/");
11                         murl = murl.replace("_", "-");
12                         murl = murl.replace("_1.aspx", "-1");
13                         location.replace(murl);
14                     }
15                 }
16             } catch (err) { }
17         }
18 </script>
19 <script type="text/javascript">
20     uaredirect(document.URL);
21     </script>

今天遇到一个移动端和PC端网址相差比较大的情况,要做跳转需要做一些替换。

PC端的网址是***.com/ask/question_123_1.aspx

移动端网址是***.com/touch/question-123-1

就是替换掉PC网址中的ask,_和_1.aspx

标签:murl,PC,replace,网址,跳转,js,aspx
From: https://www.cnblogs.com/jingccj/p/17765639.html

相关文章

  • mdbook pdf 修改超链接为页内跳转、添加目录
    rust很多文档都是mdbook,打印成pdf后发现页内的链接跳转到浏览器,而且没有书签目录。功能修改超链接为页内跳转如图蓝色链接,一般点击会跳转至浏览器,经过程序处理后会直接在pdf内跳转添加目录使用使用浏览器打印pdf(火狐测试通过)pythonmdbook.py-uURL-ppdf位置URL是......
  • vue js获取当天日期
    <template><div><p>Todayis{{today}}</p></div></template><script>exportdefault{data(){return{today:''}},mounted(){this.today=this.getCurrentDate();......
  • nbcio-boot升级springboot、mybatis-plus和JSQLParser后的LocalDateTime日期json问题
    升级后,运行显示项目的时候出现下面错误2023-08-1210:57:39.174[http-nio-8080-exec-3][1;31mERROR[0;39m[36morg.jeecg.common.aspect.DictAspect:104[0;39m-json解析失败Java8date/timetype`java.time.LocalDateTime`notsupportedbydefault:addModule"com.faster......
  • nbcio-boot升级到3.1后出现online表单新增报错       nbcio-boot升级springboot、
        nbcio-boot升级springboot、mybatis-plus和JSQLParser后出现新增online表单的时候报错,如下: 2023-08-1321:18:01.292[http-nio-8080-exec-12][1;31mERROR[0;39m[36mo.jeecg.common.exception.JeecgBootExceptionHandler:69[0;39m-Handlerdispatchfailed;neste......
  • js对json数组中的json对象去重
    实现思路:使用map()方法将JSON对象转换为字符串,并使用Set对象去除重复项。然后,我们将字符串再次转换为JSON对象,并使用Array.from()方法将其转换为数组。这样,我们就得到了一个去重后的JSON对象数组。 letarr=[{name:'zhangsan',age:10},{name:'lisi',age:30},{name:'zha......
  • 一个vuepress配置问题,引发的js递归算法思考
    前言这两天在尝试用语雀+vuepress+github搭建个人博客。小破站地址:王天的web进阶之路语雀作为编辑器,发布文档推送github,再自动打包部署,大概流程如下。问题我使用的elog插件批量导出语雀文档。elog采用的配置是所有文章平铺导出,没有按照语雀知识库目录生成markdown,这导......
  • 2023.10.14 js事件监听
    //方式一<inputtype="button"onlick="on()"value="按钮1"><script>functionon(){alert("我被点击了~");}</script>//方式二<inputtype="button"id="btn"value="按钮......
  • 在Node.js项目中使用node-postgres连接postgres以及报错指南
    什么是node-postgres官方文档nodepostgres是node.js模块的集合,用于与PostgreSQL数据库接口。它支持回调、promise、async/await、连接池、准备好的语句、游标、流式结果、C/C++绑定、富类型解析等等!就像PostgreSQL本身一样,它有很多功能:本文档旨在让您快速、正确地运行。它还试图......
  • jsoup获取指定class名称的标签
      publicvoidloadHtmlFile(StringhtmlFilePath){try{Documentdoc=Jsoup.parse(newFile(htmlFilePath),"utf-8");Elementsdivs=doc.select("div.hop1");for(Elementdiv:divs){......
  • Servlet/JSP
    Servlet/JSPIDEA配置然后可以看到默认给你一个HelloWorld然后注意端口占用的问题HelloWorld项目源码index.jsp(src/main/webapp/WEB-INF/index.jsp)<%@pagecontentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtml><html>......