[英]Open a Local link in a new tab
我有一個場景,我在超鏈接中鏈接文本中的所有 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);
你能提煉一下你的問題嗎,你要問什么還不是很清楚?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.