良いタイトルを考えることができません申し訳ありません! どうしますか? 私はajsonファイルはビットこの「https://google.com/index.html \の疲れをあなたのn \ nはなぜhttps://bing.com/index.htmlをしようとしない」私はそれが何をしたいのは何もっと1つの価値を得ること
が を[完了]をクリックしますリンクは上のテキストを表示したテキストを作るあるように見えるしていURLのドメインになるだけのページ たとえばgoogle.com
私はそれまでのところ作業しています。最初のURLはすべて正しくフォーマットされていますが、2番目のURLは正しく表示されません。
var url = "You tired of https://google.com/index.html \n\n why not try https://bing.com/index.html ";
linkify(url);
function linkify(url) {
alert(url);
var domain;
//find & remove protocol (http, ftp, etc.) and get domain
if (url.indexOf("://") > -1) {
domain = url.split('/')[2];
}
else {
domain = url.split('/')[0];
}
//find & remove port number
domain = domain.split(':')[0];
alert(domain);
var replacedText, replacePattern1, replacePattern2, replacePattern3;
//URLs starting with http://, https://, or ftp://
replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
replacedText = url.replace(replacePattern1, '<a href="$1" target="_blank">'+domain+'</a>');
//URLs starting with "www." (without // before it, or it'd re-link the ones done above).
replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">'+domain+'</a>');
//Change email addresses to mailto:: links.
replacePattern3 = /(([a-zA-Z0-9\-\_\.])[email protected][a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
document.getElementById('out').innerHTML = replacedText;}
<span id="out"></span>
それはうまく動作します。ありがとう、しかし、リンクの数がポストとポストと異なる場合、それはちょっとしたヒットやミスかもしれません。私はちょうど[1]から[2]に変わることができることを知っています。あなたのやり方はより構造化されています。 –