Get current URL with jQuery?
Posted By: venkatachalam
I am using jQuery. How do I get the path of the current URL and assign it to a variable?
Example URL:
http://localhost/menuname.de?foo=bar&number=0
Solution
To get the path, you can use:
var pathname = window.location.pathname; // Returns path only (/path/example.html)
var url = window.location.href; // Returns full URL (https://example.com/path/example.html)
var origin = window.location.origin; // Returns base URL (https://example.com)
Answered By: Ryan Doherty
Related Articles
- Error 'Map', but got one of type 'Null' flutter web…
- What is the origin of foo and bar?
- TLS 1.3 server socket with Java 11 and self-signed…
- Usage of __slots__?
- easiest way to extract Oracle form xml format data
- Issue with iron-ajax request
- Generate sequence of dates for given frequency as…
- dynamic_cast and static_cast in C++
- How can I integrate javascript hot reload into…
- Fix top buttons on scroll of list below
- Difference between variable declaration syntaxes in…
- How can I switch to another branch in git?
- Creating an instance of class
- Error when running tests in VueJS: Unknown custom element:
- Design DFA accepting binary strings divisible by a…
- How do I pass a unique_ptr argument to a constructor…
- Is this request generated by EF Core buggy or is it my code?
- Using aurelia-cli unable to get bootstrap and a…
- How can I resolve Web Component Testing error?
- Transferring JavaScript objects to HTML table
- pandas: best way to select all columns whose names…
- How can I create a Promise in TypeScript from a union type
- What is your most productive shortcut with Vim?
- How does origin/HEAD get set?
- JUNIT @ParameterizedTest , Parameter resolution Exception
- Error in styles_base.xml file - android app - No…
- XMLHttpRequest cannot load ✘✘✘ No…
- Make: "nothing to be done for target" when invoking…
- Error: container has not been made global - how to solve?
- How to sort an array in descending order in Ruby
- Reactive declarations seems not work? Or am I using…
- Why cat does not work with parameter -0 in xargs?
- Vue.js - prop sync not instant
- Class vs. static method in JavaScript
- What is causing this broken animation/transition in…
- Why do git fetch origin and git fetch : behave differently?
- useEffect Error: Minified React error #321 (GTM…
- What are the currently supported CSS selectors…
- What does "Fatal error: Unexpectedly found nil while…
- How to type mutable default arguments
- How do i arrange images inside a div?
- Accessing query values in Next.js
- Good way of getting the user's location in Android
- No 'Access-Control-Allow-Origin' header is present…
- Polymer events from distant nodes
- What is the best way to declare global variable in Vue.js?
- How do I approach solving this problem: Cannot…
- Can you pre-load related data such that your…
- String concatenation with Groovy
- Attempt to use Aurelia plugin causing 404 error in browser
- Is it possible to apply CSS to half of a character?
- Why do I have to "git push --set-upstream origin "?
- Ways to circumvent the same-origin policy
- Detecting when Partial extends T
- Aurelia customAttribute not working
- How to set sub-properties in read-only Polymer 1.x…
- What is the correct way to split an aurelia app into…
- How the int.TryParse actually works
- Callback functions in C++
- Understanding PrimeFaces process/update and JSF…
- Equals implementation with override Equals,…
- How to select rows from a DataFrame based on column values
- difference between pygame and pygame.SOMETHING
- Why call git branch --unset-upstream to fixup?
- NextJS: Specify Common Rendering Template
- C++ Passing Pointer to Function (Howto) + C++…
- Vue project tests are failing when I added vue-i18n…
- Why is it that "No HTTP resource was found that…
- Getting Monaco to work with Vuejs and electron
- How to pass parameters using ui-sref in ui-router to…
- Converting an Object to an array of KV values
- How to serialise only name of variant and ignore…
- Aurelia not dirty checking function result in HTML…
- Converting a Java Keystore into PEM Format
- Pass props in Link react-router
- A variable modified inside a while loop is not remembered
- How to do a multi check for null values after Dart…
- How can I manually compile a svelte component down…
- Solve Cross Origin Resource Sharing with Flask
- Passing variables, creating instances, self, The…
- ClassNotFoundException:…
- CSS Selector that applies to elements with two classes
- Git merge with force overwrite
- What are the recommendations for html tag?
- What's the difference between using "let" and "var"?
- Unhandled Promise Rejection when trying to call…
- How do i update a javascript variable as its value changes?
- Running multiple AsyncTasks at the same time -- not…
- Dynamically update values of a chartjs chart
- Polymer paper-dialog: how can I know when an…
- NextJS deploy to a specific URL path
- How can I find the location of origin/master in git,…
- Regex lookahead, lookbehind and atomic groups
- How to parse an RSS feed using JavaScript?
- Understanding repr( ) function in Python
- JS search in object values
- Default property value in React component using TypeScript
- Parsing Query String in node.js
- Active tab issue on page load HTML
- how to get the extender or implementer child's Type
Disclaimer: This content is shared under creative common license cc-by-sa 3.0. It is generated from StackExchange Website Network.