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

How to get Current url path

// Full URL with query string
print $request->fullUrl(); // http://127.0.0.1:8000/sometext?city=hyd

// Get the path part of the URL 
print $request->path(); // sometext

// Root (protocol and domain) part of the URL)
print $request->root(); //http://127.0.0.1:8000

//Get the full URL for the previous request
print url()->previous();

//tested on Laravel 5.6

//OR 

use IlluminateSupportFacadesURL;
 
print URL::current();
Comment

PREVIOUS NEXT
Code Example
Javascript :: isoddjs 
Javascript :: generate random number javascript 
Javascript :: use icon in node js html 
Javascript :: jquey check css style 
Javascript :: nangular make window available 
Javascript :: jquery if checkbox checked 
Javascript :: js event listener url change 
Javascript :: if media query jquery 
Javascript :: ngfor on keys of a dictionary angular 
Javascript :: how to get element by attribute value in javascript 
Javascript :: jquery if null or empty 
Javascript :: clear async storage react native 
Javascript :: gradlew clean in react native 
Javascript :: $(document).ready | document.ready 
Javascript :: on click fade out jquery 
Javascript :: lowercase or uppercase all strings in array javascript 
Javascript :: jquery onchange input value 
Javascript :: for loop in ejs 
Javascript :: base64 decode javascript 
Javascript :: npm react hook form 
Javascript :: javascript count elements in json object 
Javascript :: set padding jquery 
Javascript :: check if is array js 
Javascript :: select2 get selected value 
Javascript :: converting binary to text js 
Javascript :: javascript get seconds between two dates 
Javascript :: js check string for pangram 
Javascript :: generate random numbers in js 
Javascript :: angular component between tags 
Javascript :: javascript sort chars in string 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =