Javascript 在新选项卡中打开本地链接
我有一个场景,我在一个超链接中链接文本中的所有URL。但当用户键入www时,浏览器将其作为本地URL,并将链接绑定到应用程序URL 我想知道如何在新选项卡中打开本地URLJavascript 在新选项卡中打开本地链接,javascript,jquery,html,Javascript,Jquery,Html,我有一个场景,我在一个超链接中链接文本中的所有URL。但当用户键入www时,浏览器将其作为本地URL,并将链接绑定到应用程序URL 我想知道如何在新选项卡中打开本地URL var replaceTextWithURL = systemNotificationText.replace(/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a
var replaceTextWithURL = systemNotificationText.replace(/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi, function(text, link) {
console.log(text, link);
return '<a href="' + link + '" class="systemNotificationExtLink" target="_blank"> ' + link + ' </a>';
//var httpUrl = link.startsWith("http");
//var httpsUrl = link.startsWith("https");
//if (httpUrl || httpsUrl) {
// return '<a href="' + text + '" target="_blank" class="systemNotificationExtLink"> ' + text + ' </a>';
//}
//else {
// return '<a href="http://' + text + '" target="_blank" class="systemNotificationExtLink"> ' + text + ' </a>';
//}
});
var newLineText = replaceTextWithURL.replace(/\r?\n/g, '<br />');
$("#systemNotificationPreview").html(newLineText);
[代码>var-REPLAC>var-REPLAC>var-REPLAC>var-REPLATETETETETENCC<编码>var>var>var>var>var>var>var>var>var-REPLATETETETETETETEC”); $(“#系统通知预览”).html(newLineText);
你能改进你的问题吗,你的问题不太清楚吗?当你添加a href=“www.google.com”时。它将附加在网站URL之后。例如stackoverflow.com/google.com。链接没有在新窗口中打开。我已经给出了解释/答案。请查收。