Checking URL regardless of server

1

I need to check the URL of a page in JavaScript. I'm displaying the following alert:

alert(window.location.href.toString())

The following ULR is displayed in the alert:

http://localhost:9577/Painel/Index

I can not compare the entire string returned because the server will not always be localhost:9577 . How do I check only the /Painel/Index directory regardless of the server?

    
asked by anonymous 28.09.2016 / 21:17

1 answer

1

The object window.location has some properties that will help you:

In your case, window.location.pathname will return the information you need. The exception will be for pages that implement URLs such as "mysite.com/site".

    
28.09.2016 / 21:21