[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);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM