zoukankan      html  css  js  c++  java
  • [Vue] vue跳转外部链接

    问题

    vue 跳转外部链接问题,当跳转的时候会添加在当前地址后面

    var url = 'www.baidu.com'
    
    //跳转1
    window.localtion.href = url
    
    //跳转2
    window.history.pushState(url);
    window.history.replaceState(url);
    
    //跳转3
    window.open(url,"_blank");
    
    //跳转4
    var a = document.createElement("a");
    a.setAttribute("href", "www.baidu.com");
    a.setAttribute("target", "_blank");
    a.click();
    
    http://192.168.0.139:8080/#/
    http://192.168.0.139:8080/www.baidu.com#/
    

    这时将 url 前面添加响应的 (http:// 或 https://)

    var p = window.location.protocol;
    var a = document.createElement("a");
    a.setAttribute("href", `${p}//www.baidu.com`);
    a.setAttribute("target", "_blank");
    a.click();
    document.getElementsByTagName("body")[0].appendChild(a);
    
  • 相关阅读:
    Python之路Day02
    Python之路Day01
    Python 常用单词
    JS-向数组添加元素
    JS-lambda表达式
    正则表达式问记录
    JDBC学习
    jquery常用选择器
    mongodb学习
    java8 lambda表达式
  • 原文地址:https://www.cnblogs.com/mybilibili/p/10318675.html
Copyright © 2011-2022 走看看