How to edit a url with JS?

2

In the JS that I am developing, I must enter and / or use a url dinámica in case the project name changes ...

For this reason, try using the following:

alert(window.location.pathname);

which shows me the following /proyecto/index.php/usuario/

How could I modify this (window.location.pathname) in such a way that it does not show me the name of the controller that in this case is usuario if not only this? /project/index.php /

I would appreciate immensely if you can help me with this.

    
asked by JDavid 06.04.2017 в 15:18
source

2 answers

1

If you intend to do it with Javascript, try history.pushState , with this you can change the addresses.

According to Mozilla , how you should do it is:

<script type="text/javascript>
    var stateObj = { estado: "ok" };
    history.pushState(stateObj, "página 2", "dirección.html");
</script>

This will cause the browser to display the address http://midominio/dirección.html but without redirecting or checking if dirección.html exists.

    
answered by 06.04.2017 в 15:26
1

path=window.location.pathname;
alert(path.substr(0,5+path.indexOf(".php")));
    
answered by 07.04.2017 в 04:40