URL checking independently of the server

Asked

Viewed 32 times

1

I need to check the URL from a Javascript page. I am displaying the following Alert:

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

The following ULR is displayed on Alert :

http://localhost:9577/Painel/Index

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

1 answer

1


The object window.location has some properties that will help you:
inserir a descrição da imagem aqui
In your case, window.location.pathname will return the information you need. The exception will be for pages that implement Urls such as "meusite.com.br/site".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.