Results 1 to 2 of 2

Thread: How to modify this code to add more clickable links to it?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jun 2018

    How to modify this code to add more clickable links to it?

    Hi all,
    I have this code from here
    Here the code
           function sendFunction() {
               var userName = document.getElementById("myUserName").value;
               var userinput = document.getElementById("myInput").value;
               var imagesrc = document.getElementById("baseimage");
     var img = $('<img width=" =100px;" height=" 100px">').attr('src', imagesrc.value);
        $('#conDivID').append("<span style='color: red'>" + userName + ': </span>');
        $('#conDivID').append("<span style='color: blue'>" + embedUrls(userinput) + ' </span>');
        $('#conDivID').append("<span class='timeSpan'>" + timestring + '</span>');
        function embedUrls(text) {
            var urlRe = /(https?:\/\/[^\s]+)/g;
            return text.replace(urlRe, '<a href="$1">$1</a>');
    And I try it and it works as it say.
    But is
    it possible to :-
    1-Make it open in a new window " target="_blank"?
    2-Include the code links end with .com,.net,.org,.om,.us,.uk,.sa,.gov etc.
    such as"google.com"?
    3-Make it open phone numbers if user uses my site on his mobile and send phone number it should be clickable ?
    4-Include it email address to be clickable.

    Thanks for your valuable time
    Last edited by Max45; Nov 28th, 2018 at 06:51 PM.

  2. #2
    March 2015 Winner kfcSmitty's Avatar
    Join Date
    May 2005
    Kingston, Ontario

    Re: How to modify this code to add more clickable links to it?

    For #1, #2, and #4, what have you tried? The code already looks like it would work for .com, .net, .org, etc. Have you tried it?

    Have you read and understood the code? If you're familiar with HTML at all, there is one line in that code that should make it extremely obvious how to add the target="_blank" to the anchor.

    You also shouldn't make a double post. Your previous reply to the other thread wasn't answered because you didn't specify enough information and because you didn't actually try anything yourself.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts


Click Here to Expand Forum to Full Width