Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript get url path

window.location.pathname
Comment

js url pathname

var getLocation = function(href) {
    var l = document.createElement("a");
    l.href = href;
    return l;
};
var l = getLocation("http://example.com/path");
console.debug(l.hostname)
>> "example.com"
console.debug(l.pathname)
>> "/path"
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 if else click function 
Javascript :: filter method javascript 
Javascript :: javascript string spaces replace with %20 
Javascript :: javascript remove function from object 
Javascript :: headless ui modal 
Javascript :: alternative to setinterval 
Javascript :: template literals 
Javascript :: events onclick 
Javascript :: angular on back skip routes 
Javascript :: how to use msg.send instead of msg.reply discord.js javascript 
Javascript :: object literal js 
Javascript :: render partial in js.erb 
Javascript :: javascript import module 
Javascript :: jquery get name value method 
Javascript :: check if an input element has focus 
Javascript :: how to pass callback function in javascript 
Javascript :: chrome extension catch shortcut 
Javascript :: javascript function with string parameter 
Javascript :: math floor javascript 
Javascript :: mongoose find in array 
Javascript :: $(...).editableSelect is not a function 
Javascript :: js remove all children 
Javascript :: strupper in js 
Javascript :: document ready vanilla js 
Javascript :: disable textbox on plumsail 
Javascript :: leave page 
Javascript :: import json file into javascript 
Javascript :: javascript scroll to element with offset 
Javascript :: JavaScript max 32-bit integer 
Javascript :: js user add names to a list on screen 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =