Readdy Write  
0,00 €
Your View Money
Views: Count
Self 20% 0
Your Content 60% 0

Users by Links 0
u1*(Content+Views) 10% 0
Follow-Follower 0
s2*(Income) 5% 0

Count
Followers 0
Login Register as User

Javascript: exchange text with link through a link

03.05.2018 (👁2788)


 

In this Javascript code example, a web address, which you enter as text in the draft, is automatically displayed as a link in the output display.

To do this, Javascript checks for content after loading the page into http: // or http: //.

 

Javascript code example

 

function replace_all_Text_Links() {

    //--------< replace_all_Text_Links() >--------

    //*replace Video Embed   

    var divContent = document.getElementById("divContent");

    var elements = divContent.getElementsByTagName("P");

 

    //< loop: children >

    for (var varLine of elements) {

        //----< check_line >----

 

        var sText_Original = varLine.innerText;

        var sText = sText_Original.toLowerCase();

        var posStart = sText.indexOf("http://");

        if (posStart == -1) { posStart = sText.indexOf("https://"); }

        if (posStart > -1) {

            var posEnd = sText.indexOf(" ", posStart);

            if (posEnd < 0) posEnd = sText.length - 1;

            var sURL = sText_Original.substring(posStart, posEnd);

            //< replace >

            //--< Create YT_Video >--

            var link = document.createElement("A");

            link.setAttribute("rel", "nofollow");

            link.setAttribute("href", sURL);

            //--</ Create YT_Video >--

 

            //< xchange >

            varLine.parentNode.insertBefore(link, varLine);

            link.appendChild(varLine);           

            //</ xchange >

            //</ replace >           

        }

        //----</ check_line >----

    }

    //</ loop: children >

 

    //--------</ replace_all_Text_Links() >--------

}