7 examples of 'js get current url' in JavaScript

Every line of 'js get current url' 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
this disclaimer
19function read_current_url()
20{
21 mainwp_current_url = document.location.href.replace( /^.*?\/([^/]*?)\/?$/i, '$1' );
22 return mainwp_current_url;
23}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

314getCurrentUrl(): Promise<string> {
315 return promiseOf(this.browser.getCurrentUrl());
316}
7public async getUrl(): Promise<UrlWithStringQuery> {
8 return parse(await page.evaluate('location.href'));
9}
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}
41public static getPage(url: string): string {
42 let urlParts = url.split('/');
43 return urlParts[(urlParts.length - 1)];
44}
172function getCurrentCdn () {
173 if (mediaSources.length > 0) {
174 return mediaSources[0].cdn.toString();
175 }
176
177 return '';
178}
1function js(jsURL) {
2 let bundleUrl = weex.config.bundleUrl
3 let baseURL = bundleUrl.substring(0, bundleUrl.lastIndexOf("/"))
4 //是否在同级目录,若不在,则需要以下处理
5 let flag = jsURL.indexOf('../') !== -1
6 if (flag) {
7 let arr = jsURL.split('../')
8 for (let index = 0; index < arr.length - 1; index++) {
9 baseURL = baseURL.substring(0, baseURL.lastIndexOf('/'))
10 }
11 jsURL = arr[arr.length - 1]
12 }
13 return baseURL + '/' + jsURL
14}

Related snippets