Answers for "js get string from url"

10

javascript read query parameters

// example url: https://mydomain.com/?fname=johnny&lname=depp
const queryString = window.location.search;
console.log(queryString);
// ?fname=johnny&lname=depp

const urlParams = new URLSearchParams(queryString);

const firstName = urlParams.get('fname');
console.log(firstName);
// johnny

const lastName = urlParams.get('lname');
console.log(lastName);
// depp
Posted by: Guest on May-04-2020
3

get url from string javascript

function Purify(text) {
    var urlRegex = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/;
    return text.replace(urlRegex, function (url) {
        return '<a class="text-blurple" target="_blank" href="' + url + '">' + url + '</a>';
    })
}
Posted by: Guest on October-03-2021
0

get url from string javascript

var testUrl = variable.match(/'(http:[^\s]+)'/)
Posted by: Guest on August-08-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language