Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/371.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在新选项卡中打开本地链接_Javascript_Jquery_Html - Fatal编程技术网

Javascript 在新选项卡中打开本地链接

Javascript 在新选项卡中打开本地链接,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

我有一个场景,我在一个超链接中链接文本中的所有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-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-REPLATETETETETETETECvar>var>VAC>替代(替换)目前,替换(//(https????::::::以下以下以下以下以下以下以下以下以下以下)替换)替换(///(https?)替换(/(https???????????::::::::::::::::://////(以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下以下)替换(((/(https????????????????????????????????Z0-9]+\.[^\s]{2,})/gi,函数(文本,链接){ console.log(文本,链接); 返回“”; //var httpUrl=link.startsWith(“http”); //var httpsUrl=link.startsWith(“https”); //if(httpUrl | | httpsUrl){ //返回“”; //} //否则{ //返回“”; //} }); var newLineText=replaceTextWithURL.replace(/\r?\n/g,“
”); $(“#系统通知预览”).html(newLineText);
你能改进你的问题吗,你的问题不太清楚吗?

当你添加a href=“www.google.com”时。它将附加在网站URL之后。例如stackoverflow.com/google.com。链接没有在新窗口中打开。我已经给出了解释/答案。请查收。