Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript get url path

window.location.pathname
Comment

js get path from url

var reg = /.+?://.+?(/.+?)(?:#|?|$)/;
var pathname = reg.exec( 'http://www.somedomain.com/account/search?filter=a#top' )[1];
Comment

js get path from url string

function parseUrl(url) {
    var m = url.match(/^(([^:/?#]+:)?(?://((?:([^/?#:]*):([^/?#:]*)@)?([^/?#:]*)(?::([^/?#:]*))?)))?([^?#]*)(?[^#]*)?(#.*)?$/),
        r = {
            hash: m[10] || "",                   // #asd
            host: m[3] || "",                    // localhost:257
            hostname: m[6] || "",                // localhost
            href: m[0] || "",                    // http://username:password@localhost:257/deploy/?asd=asd#asd
            origin: m[1] || "",                  // http://username:password@localhost:257
            pathname: m[8] || (m[1] ? "/" : ""), // /deploy/
            port: m[7] || "",                    // 257
            protocol: m[2] || "",                // http:
            search: m[9] || "",                  // ?asd=asd
            username: m[4] || "",                // username
            password: m[5] || ""                 // password
        };
    if (r.protocol.length == 2) {
        r.protocol = "file:///" + r.protocol.toUpperCase();
        r.origin = r.protocol + "//" + r.host;
    }
    r.href = r.origin + r.pathname + r.search + r.hash;
    return r;
};
parseUrl("http://username:password@localhost:257/deploy/?asd=asd#asd");
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery get data attribute value by class 
Javascript :: how to check if username already exists in database using javascript 
Javascript :: js remove english word from string 
Javascript :: remove duplicated from array 
Javascript :: regex contains special characters javascript 
Javascript :: componentdidmount in hooks 
Javascript :: componentdidmount react hooks 
Javascript :: Min JavaScript Methods 
Javascript :: javascript redirect to file 
Javascript :: react navigation 
Javascript :: preventing form from submitting 
Javascript :: npm install save shortcut 
Javascript :: nested array in json 
Javascript :: what is ajax 
Javascript :: what is shortest javascript program 
Javascript :: make service singleton angular 
Javascript :: how to draw a flower in javascript 
Javascript :: faker js uuid example 
Javascript :: return new Promise(res = { 
Javascript :: schema in mongoose 
Javascript :: vue state 
Javascript :: react native image from web 
Javascript :: ion change ionic angular 
Javascript :: email valid javascript 
Javascript :: javascript string objects 
Javascript :: react spread operator 
Javascript :: how to display image in html from json object 
Javascript :: how to use promise.all 
Javascript :: js create a auto call function inside function 
Javascript :: angular indexeddb 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =