解决JS请求路径控制台报错 Failed to launch'xxx' because the scheme does not have a registered handler

作者:代码拾荒

时间:2026-10-26

浏览:374

本文针对控制台报错“Failed to launch 'xxx' because the scheme does not have a registered handler”进行解析。该错误通常由URL缺少协议头(如http://)引起,通过补充完整协议前缀即可解决。此外,文章还介绍了在JavaScript中获取URL查询参数的方法及基于参数控制Tab切换的实际应用。

文章目录

控制台输出错误信息:Failed to launch ‘xxx’ because the scheme does not have a registered handler。

出现此类错误的原因在于请求链接未包含协议头,需要在URL前显式添加协议标识。

以下是导致该错误的代码示例:

window.location.href="localhost:8080/goShowJSP"

修正后的正确代码示例如下:

window.location.href="http://localhost:8080/goShowJSP"

扩展知识:如何在JS中获取请求路径中的参数值

提取URL查询参数的方法

function getQueryString() {  
  var qs = location.search.substr(1), // 获取url中"?"符后的字串  
    args = {}, // 保存参数数据的对象
    items = qs.length ? qs.split("&") : [], // 取得每一个参数项,
    item = null,
    len = items.length;
 
  for(var i = 0; i < len; i++) {
    item = items[i].split("=");
    var name = decodeURIComponent(item[0]),
      value = decodeURIComponent(item[1]);
    if(name) {
      args[name] = value;
    }
  }
  return args;
}

针对形如 http://localhost/index.html?q1=abc&q2=efg&q3=h 的URL,获取 q1 参数值的具体实现方式如下:

实际应用场景中,可根据获取到的请求参数来控制前端Tab标签页的切换逻辑。

$(document).ready(function(){
        
        $("#1").click(function(){
            $(".bidinfo-tab li").removeClass("current");
            window.location.href="/m/front/invest/investList"
        })
        $("#2").click(function(){
            $(".bidinfo-tab li").removeClass("current");
            window.location.href="/m/front/invest/investList?type=1"
        })
        $("#3").click(function(){
            $(".bidinfo-tab li").removeClass("current");
            window.location.href="/m/front/invest/investList?type=2"
        })
                        
        
        var type=location.search.substr(1).split("=")[1];
        if(type=="1"){
            $("#2").addClass("current")
        }else if(type=="2"){
            $("#3").addClass("current")
        }else{
            $("#1").addClass("current")
        }
    })

至此,关于解决JS请求路径控制台报错 Failed to launch'xxx' because the scheme does not have a registered handler的问题介绍完毕。如需了解更多相关js请求路径控制台报错内容,请搜索本站以前的文章或继续浏览下面的相关文章,希望大家以后多多支持本站!

实用工具推荐

电子包浆

绿化、压缩、噪点和虚拟水印,自由调节做旧程度。

使用 ›
图片压缩

选择画质和输出格式,预览压缩前后的大小。

使用 ›
相关文章