Saturday, 31 August 2013

Url Detection using Jscript

Url Detection using Jscript

This is the javascrip that i have implemented for url detection in a plain
text but when i am clicking on the link i am not able to open the link in
new tab it is opening the localhost address before the website.
Example : i have detected www.google.com
when i am clicking on it i am getting this
(localhost:3415/Home/www.google.com)
i want only www.google.com to be open in new tab
<-- Code -->
<script type="text/javascript">
function test() {
dt(document.getElementById('d').value);
}
function dt(t) {
// find links wo www and http. bla.bla.TLD(ANY query)
var srg = new
RegExp(/(^|\b)([\w.]+\.[a-z]{2,3}(?:\:[0-9]{1,5})?(?:\/.*)?)([,\s]|$)/ig);
var r = t.replace(srg, '$1<a href="$2" target="_blank">$2</a>');
document.getElementById('c').innerHTML = r;
}
</script>

No comments:

Post a Comment