Skip to content

Instantly share code, notes, and snippets.

@GreeeenApple
Last active February 17, 2017 15:56
Show Gist options
  • Save GreeeenApple/6fa9347bb1a53617e573f1b23e2613f3 to your computer and use it in GitHub Desktop.
Save GreeeenApple/6fa9347bb1a53617e573f1b23e2613f3 to your computer and use it in GitHub Desktop.
<html>
<body>
<div id="hoge">
<!-- ここにタグ文字がエスケープされた(>や<は&gtや&lt)任意の文字列が入れられる -->
</div>
<script>
function f(){
var txt = document.getElementById("hoge").innerHTML;
txt = txt.replace(/(http:\/\/[\x21-\x7e]+)/gi, '<a href="http://redirect.com/$1" onmousedown="f=' + "'1'" + ';" target=\"_b\">$1</a>');
txt = txt.replace(/(https:\/\/[\x21-\x7e]+)/gi, '<a href="http://redirect.com/$1" onmousedown="f=' + "'1'" + ';" target=\"_b\">$1</a>');
document.getElementById("hoge").innerHTML = txt;
}
f();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment