10 examples of 'window location href split' in JavaScript

Every line of 'window location href split' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
11function splitFragment(url: string): [string, string?] {
12 const [pathAndQuery, fragment] = url.split(/#(.+)?/, 2);
13
14 // Strip any trailing slashes off the path, to match ember's treatment
15 return [pathAndQuery.replace(/\/+(?=($|\?))/, ''), fragment];
16}
310public getPath(full: boolean = false): string {
311 if (full) {
312 return this.location.href;
313 }
314 const hash = this.location.hash.substring(1);
315 return hash.split('?')[0];
316}
12function getWindowHash() {
13 let hash = window.location.hash.replace(/^#\/?|\/$/g, '');
14
15 //Do not include state
16 hash = hash.split(URL_STATE_DELIM)[0];
17
18 //console.log('hash:', hash);
19 return hash;
20}
16function parseURL(){
17 var res = {}, search = location.search;
18 if (search.indexOf("?") != 0){
19 return res;
20 }
21 search = search.substr(1).split("&");
22 for (var i = 0; i < search.length; ++i){
23 var
24 item = search[i],
25 idx = item.indexOf("="),
26 k = item.substr(0, idx),
27 v = item.substr(idx+1);
28 res[k] = v;
29 }
30 return res;
31}
7function splitURL( url ) {
8 // First splits into main path and hash
9 url = R_SPLIT_URL.exec( url );
10 // Then splits the path into segments (delimited by slashes)
11 var tmp = url[ 1 ].match( R_ROUTE );
12 // If the path ends with a slash, removes the last empty segment
13 if ( tmp[ tmp.length - 1 ] === "/" ) {
14 tmp.pop();
15 }
16 return {
17 u: tmp,
18 h: url[ 2 ]
19 };
20}
27function locationWithoutHash() {
28 /* you can just put # on the end of url's because
29 there is a base tag that does not match the actual
30 url, its the base tag to the object, so we have
31 to reconstruct from the window.location */
32 var loc = window.location.href;
33 var hash = window.location.hash;
34 if (!hash) {
35 return loc;
36 } else {
37 return loc.substring(0, loc.lastIndexOf(hash));
38 }
39}
31function parseUrl() {
32 if (typeof document !== "undefined") {
33 const urlString = decodeURIComponent(document.location.hash)
34 if (urlString.includes('?')) {
35 const urlArray = urlString.split('?')
36 return {baseUrl: urlArray[0], encodedState: JSON.parse(urlArray[1])}
37 } else {
38 return {baseUrl: document.URL, encodedState: ''}
39 }
40 } else {
41 return {}
42 }
43}
12function parse_url(url){
13 var pathname = url || window.location.pathname;
14 pathname = pathname.replace(/^\/|\/$/g,'');
15 var path_node = pathname.split(/\//);
16 path_node[0] = '/' + path_node[0];
17 return path_node;
18}
26function getURL()
27{
28 var url = document.documentURI;
29 var match = url.match(/&u=([^&]+)&/);
30
31 // match == null if not found; if so, return an empty string
32 // instead of what would turn out to be portions of the URI
33 if (!match)
34 return "";
35
36 url = decodeURIComponent(match[1]);
37
38 // If this is a view-source page, then get then real URI of the page
39 if (url.startsWith("view-source:"))
40 url = url.slice(12);
41 return url;
42}
13function parseUrl(query) {
14 var index = query.indexOf('?');
15 if (index >= 0)
16 query = query.substring(index + 1);
17 var res = {};
18 var vars = query.split("&");
19 for (var i = 0; i < vars.length; i++) {
20 var indexPos = vars[i].indexOf("=");
21 if (indexPos < 0)
22 continue;
23
24 var key = vars[i].substring(0, indexPos);
25 var value = vars[i].substring(indexPos + 1);
26 value = decodeURIComponent(value.replace(/\+/g, ' '));
27 mergeParamIntoObject(res, key, value);
28 }
29 return res;
30}

Related snippets