All I want is to get the website URL. Not the URL as taken from a link. On the page loading I need to be able to grab the full, current URL of the website and set it as a variable to do with as I please.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
if you are referring to a specific link that has an id this code can help you.
I am using ajax here to submit an id and redirect the page using window.location.replace. just add an attribute
id=""
as stated.Gets the current page URL:
OK, getting the full URL of the current page is easy using pure JavaScript. For example, try this code on this page:
Just not bad to mention these as well:
Also if you need a relative path, simply use
window.location.pathname
;And if you'd like to get the host name, you can use
window.location.hostname
;And if you need to get the protocol separately, simply do
window.location.protocol
Also if you page has
hash
tag, you can get it like:window.location.hash
So
window.locatation.href
handles all in once... basically:Also using
window
no necessary if already in window scope...So in that case you can use:
You can get the full link of the current page through
location.href
and to get the link of the current controller, use:Firstly check for page is loaded completely in browser, then call a function which takes url, URL variable and prints on console,
Adding result for quick reference