What exactly does window.location return?

What exactly does window.location return?
0

#1

I’ve got this test alert in my document:

alert (window.location.protocol + “//” + window.location.host + “/” + window.location.pathname + window.location.search);

And the result is:

https://www.mywebsite.com/categories.php?category=toys

Does this mean that if I have a “clean” url like this one (modified inside the HTACCESS file):

https://www.mywebsite.com/categories/toys

Will window.location return what’s only inside the browser window (what we can see) or does it actually return the entire bare url?


#2

Hit F12 in your Browser and type console.log(window.location).

Then you will see, what it contains.


#3

That’s not what I meant. I want to know if it actually reads the bare url, or if it reads what we see. Because I have a function to search the url for a substring that must contain “category”, and the cleaned url doesn’t have that keyword even though in PHP it actually does.
So if window.location sees what we (humans) see then the function won’t work. I want to know how exactly it sees the url behind the scenes.


#4

Why don’t you just test it and see for yourself?


#5

I have tested it, otherwise I wouldn’t be asking. I can’t figure out if it does or doesn’t read the bare url, since I have .htaccess files reconfiguring my urls, and aliases set up on my localhost. I’m a beginner too, so it’s a little too complicated at this level.


#6

It should be what you see displayed in the console if you put console.log(window.location) in the file you want to test. If you want to “know” for sure, reload the same page after removing the url configurations in your .htaccess files.